Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Cooldown gui does not want to count down or delete?

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

1 answer

✓ Accepted answer

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.

3 comments

0

it almost fully works but the timer text still doesnt change

0

Does line 8 refer to a text-label's text? Or is there an object under Cooldown called text? If it's the former, then you're making a mistake. Remove '.text', and whenever you want to change the text (like on line 11) do cdTimer.Text.

0

i found the problem, the local for the counter text changed gui instead of gui2

This discussion is preserved as it was. New answers, comments, and votes are closed.