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

for a countdown script should I use tick or wait?

Asked by 4 years ago

I have this script where its like a game timer and when it drops to 0 it ends the game but I was wondering If I should use tick() or wait

1 answer

Log in to vote
1
Answered by 4 years ago

You could make them both work, but I'd use os.time() or tick().

local start = os.time()
local gameLength = 10
local timeRemaining = gameLength
local timeElapsed = 0
local gameInSession = true

while gameInSession do
    timeElapsed = os.time() - start
    timeRemaining = gameLength - timeElapsed
    if timeRemaining <= 0 then
        gameInSession = false
    end
    wait()
end
-- while loop yields until its conditions are met or is broken
print("Game concluded")
Ad

Answer this question