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

Text not updating as timer counts down?

So I'm making a timer for my game but when I play it, the gui gui its just stuck on "Round starting in 5 seconds!"

Important variables for code:

local TopBar = game.StarterGui.Main.TopBar 

Countdown:

for i = 5,0,-1 do
	while wait(1) do
		TopBar.Text = "Round starting in "..i.." seconds!"
		print(i)
		
		if TopBar.Text == "Round starting in 0 seconds!" then
			break
		end
	end
end

Then it breaks out of the loop and moves on.

1 answer

✓ Accepted answer

heres the fix to your problem, dont do a while loop inside of a for loop your just going to continuously loop the variable i as 5.

for i = 5,0,-1 do
	wait(1)
	TopBar.Text = "Round starting in "..i.." seconds!"
	print(i)
end

Edit: Basically so you understand, your looping inside the while loop which will never end nor will it deduct 1 from i as it hasn't reached the end of the for loop. Use a while loop if you dont know when you will get the result.

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