How can i make timer

ı tried make timer like this but there is a problem. if do addtime when time = 0 i wont be repeat again. What can i do?

local Time = 60

function AddTime(T: number)
    Time += T
end

function Something()
end

function Something2()
end

while true do
    Time -= 1
    task.wait(1)
    
    Something()    
    
    if Time == 0 then
      Something2()
      break
    end
end

If you break the loop is won’t restart because there’s no loop anymore, the easiest thing you can do is add

if Timer <= 0 then
 return 
end

It finishes the iteration of the loop and starts the next one, just make sure to add it after the wait or you’ll just crash

1 Like

break ends the loop

continue can skip one loop

while true do

    if Time == 0 then
        Something2()
        continue
    elseif Time < 0 then
        continue
    end

    Time -= 1
    task.wait(1)
    
    Something()    

end

edit: return ends execution of the entire current function so it will also end the loop in the same way as break

There’s multiple ways you can do this.

You can use tick the os clock time, a for I = amount, goal, increment loop (for I=5, 0, -1) or other variations of these systems.

All you need to do is usually just do rectime - currTime = difference if you use the clock or the tick.