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.

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
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:

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()
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