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

Why won't my timer stop going down after it reaches zero?

I'm trying to make a round timer with intermission, etc, (I have everything else set up) but the timer doesn't stop at 0, it goes into the negatives. Also, I don't know if I made the other parts correctly since I can't get past this part, thanks in advance if you are able to help.

while true do
	wait(1)
	script.Parent.Text = script.Parent.Text - 1
	if script.Value.Value == 0 then
		wait(162)
	script.Parent.Text = "Intermission"
	wait(20)
	script.Parent.Text = 60
	end
end

1 comment

0

why are you subtracting the text, and use Changed events over loops to check if a value changes.

1 answer

✓ Accepted answer

You can use a for loop instead:

function Countdown()
	for i = 60, 0, -1 do -- 60 = start, 0 = goal, -1 = step to reach goal, i = progress
		wait(1)
		script.Parent.Text = i
	end
end

function Loop()
	Countdown() -- note that any code below a for loop will not run until the loop is finished
	wait(162)
	script.Parent.Text = "Intermission"
	wait(20)
	Loop() -- repeat function
end
Loop()

7 comments

0

local functions pls

0

If you don't want to use this method you can fix your script by placing the if statement above the wait(1)

0

Thank you!

0

and change '== 0' to '<= 0' which means less than or equals to 0

1

Loop calling itself like that will eventually cause a stack overflow, I don't know the specifics, but if you instead do return Loop() on line 13 this issue won't occur.

0

You're right. Why would Loop() be returned though? Loop is void, a loop to call Loop is enough.

0

@theCJarmy7 I did what you suggested (returning loop function) and it stacked overflowed..

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