Later this will be a round-based game but for now, I’m just trying to make a timer for 600 seconds (10 minutes) and after those 10 minutes are up, will reset the timer and start all over again. I’ve managed to make a timer that sets and stops after it reaches 0, but I can’t figure out how to make the timer reset and restart.
Essentially the way I’m trying to make it work is that when a boolean called isDone is true, it will start the timer/call the function. So I start isDone as true so that the script will call the function. The function then will set isDone to false so it isn’t constantly getting called, and then when the timer is done isDone is set back to true so that the timer function is called again. Essentially it’s a loop of the function calling itself. All this does is work once though, after those 10 seconds it doesn’t reset.
local isDone = workspace.isDone.Value
isDone=true
function timer(time)
isDone=false
local timeLength=time
while timeLength> 0 and isDone==false do
task.wait(1)
timeLength = timeLength - 1
print(timeLength)
end
print("time is up")
isDone=true
end
if isDone==true then
print("starting timer")
timer(10)
end
I did 10 seconds as it’s easier to test but when it’s in my game it’ll be 600. This code will count down from 10 to 0 and stop as it should, but after that it stops. Does anyone know how to fix this?