I want to be able to break out of this loop instantly and not have to wait for it to loop again and check if the values are true so it can break. Here is my code:
-- loop
for i = gamelength, 0, -1 do
_time.Value = i
if i == 0 then
results.NoTime:Fire()
end
if #pig <= 0 then
results.NoPlayers:Fire()
end
-- checking for break
if notime or playerreachedtop or noplayers then
break
end
task.wait(1)
end
What should I do? The values that are checked are set to true via bindable events.
change the task.wait(1) to a loop that compares time passed through the tick() or time() function. have it break out of THAT loop once one of the conditions are met or the desired time has passed. you’d have to nest the loop.
local StartTime = time()
local WaitTime = 1 -- time to wait, 1 second in this case
repeat
task.wait()
until time() - StartTime >= WaitTime or notime or playerreachedtop or noplayers