Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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.

01while true do
02    wait(1)
03    script.Parent.Text = script.Parent.Text - 1
04    if script.Value.Value == 0 then
05        wait(162)
06    script.Parent.Text = "Intermission"
07    wait(20)
08    script.Parent.Text = 60
09    end
10end
0
why are you subtracting the text, and use Changed events over loops to check if a value changes. User#19524 175 — 6y

1 answer

Log in to vote
3
Answered by 6 years ago

You can use a for loop instead:

01function Countdown()
02    for i = 60, 0, -1 do -- 60 = start, 0 = goal, -1 = step to reach goal, i = progress
03        wait(1)
04        script.Parent.Text = i
05    end
06end
07 
08function Loop()
09    Countdown() -- note that any code below a for loop will not run until the loop is finished
10    wait(162)
11    script.Parent.Text = "Intermission"
12    wait(20)
13    Loop() -- repeat function
14end
15Loop()
0
local functions pls User#19524 175 — 6y
0
If you don't want to use this method you can fix your script by placing the if statement above the wait(1) awesomeipod 607 — 6y
0
Thank you! CaptainAlien132 225 — 6y
0
and change '== 0' to '<= 0' which means less than or equals to 0 awesomeipod 607 — 6y
View all comments (3 more)
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. theCJarmy7 1293 — 6y
0
You're right. Why would Loop() be returned though? Loop is void, a loop to call Loop is enough. User#19524 175 — 6y
0
@theCJarmy7 I did what you suggested (returning loop function) and it stacked overflowed.. awesomeipod 607 — 6y
Ad

Answer this question