For 4 consecutive days, I've been looking for a solution to stop a script from performing its waiting task after the wait(1) has been ran. I want to stop the script from waiting in the middle whilst waiting.
The only conclusion I've come up with is to do script:Destroy() and then re-clone it but I rather avoid doing that.
Is there any way I can make this work?
while wait(5) do print("Script is waiting 5 seconds but I want it to break the while loop while it's waiting.") end --Outside function or method to break this while loop before wait() re-runs task? ^
You could use break
for stopping the loop, or if you want it to stop after a specific time, use for loops, just like this example:
for i = min, max do -- function end
Hope I helped.
Found out the solution on my own.
ifStepped = true function clock() spawn(function() for i = 1, 10 do i = i + 1 wait(0.1) if i == 10 then --[[If one second complete then we can re-run clock. can also use this and modify this if statement to see if the player stepped out of the region to stop the timer. This way when the player re-joins Region3 the timer / player points re-start exactly from 0. --]] print("broke") ifStepped = true break end end end) end spawn(function() while wait(0.1) do --This while loop checks if player is in a region3 (just an example) print("Ran") --Running the 1 second to see if player stepped out of region if ifStepped == true then ifStepped = false --If this is true we run clock and we changed it to false not to run clock again. clock() end end end)