for some reason the game freezes for like 10 seconds when i fireserver the cdgui script, and the counter doesnt want to go down
and it doesnt want to destroy after its finished counting
game:GetService("ReplicatedStorage").CooldownGui.OnServerEvent:Connect(function(player, movename, countdown, localorglobal) local chr = player.PlayerGui local timer = countdown local gui2 = game:GetService("ServerStorage")["CDGui"]:Clone() gui2.Parent = chr chr.CDGui.Name = "cooldown" local gui = chr.cooldown local cdtimer = gui.MainFrame.Cooldown.Text gui.MainFrame.MoveName.Text = movename cdtimer = countdown cdtimer.Enabled = true coroutine.resume(coroutine.create(function() repeat until timer == 0 wait(1) timer = timer - 1 cdtimer = cdtimer - 1 end)) wait(countdown) gui:Destroy() end)
im not sure what is wrong with the code tho
You should rewrite your script. It's very awfully written and doesn't seem like you know what you're doing.
First of all, you don't use a repeat ... until ...
loop like that. You also don't need a coroutine there, and if you do remove the coroutine then remove line 19.
They work like this:
repeat function() until condition
Lines 14 to 17 should instead be:
repeat cdtimer.Text = timer -- you cannot minus a string from itself, it will error. wait(1) timer -= 1 -- or timer = timer - 1 until timer <= 0
The way you're doing it lags the game because repeat
here will function the same as a while true do
loop without and yielding (waits). When it times out, the script stops, nothing will work.