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

Is this the best way to make a countdown timer?

Asked by
LawlR 182
5 years ago

I'm making a round based game, which ends once a timer reaches 0. Is the best way to do it to create a loop in a coroutine and take away 1 every second, or is there a better way?

0
just use a for loop User#19524 175 — 5y
0
Right, I was thinking that it wouldn't work if there's code below it, but I forgot you can just break it. LawlR 182 — 5y
0
repeats work greatneil80 2647 — 5y
0
No need to break 'for loops'. After a for loop reaches it's max it will end the loop. Pojoto 329 — 5y
0
Right right, it's pretty late, I'm not thinking straight. LawlR 182 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

You can place the for loop in a spawn function() and any code below it should run.

spawn(function()
    for i = 60, 0, -1 do 
        wait(1)
        print(i .. " seconds left.")
    end
end)

print("test")
0
Thanks, this helped. LawlR 182 — 5y
Ad

Answer this question