Is there a way to put a timer on 'break'

After while true do
is there a way to put ‘break’ on a timer?
Question
I did look before I posted this

1 Like

What do you mean my a timer? If you want to yield the thread for a certain amount of time use wait() as so: while true do wait() break end.

I want the loop to continue for a certain amount of time.

To do this just wait until the time is met

local keepGoing = true

local function timer()
    wait(6)
    keepGoing = false
end

spawn(timer)

while keepGoing do
    wait()
end

Adding onto @Faultsified post. This is a method of doing this. But using spawn() and having a wait() isn’t at all needed. You can instead use delay() in order to avoid using an unneeded wait().

local DoLoop = true

delay(6, function()
	DoLoop = false
end)

while DoLoop do
	wait()
end
2 Likes

Or

local t = tick() + 6
while tick()<t do
    -- whatever you want, which could include a wait() to yield
end
1 Like