Hi, I am trying to figure out what is the best way to halt my code until either a certain amount of time has passed or a condition has been met.
Here is the pseudocode for what I am currently thinking, but I am not sure if this is the best way to do so.
while conditionNotMet and os.difftime(os.time(), startTime) ~= timeInWholeSeconds do
wait()
end
and maybe for a more specific time constraint (partials of seconds), you could spawn another function that waits the specific time and sets a boolean value that is part of the original while loop.
Forgive me if the solution is simple.
Edit: Cleaner version could be
repeat wait() until (conditionMet or os.difftime(os.time(), startTime) == timeInWholeSeconds)
There should not need to be a reason. I am just inquiring what the best way to do that would be. It could do something such as wait until an objective is complete or until the players are out of time.
In that case I would make a timer and a bindable event that fires when the objective is complete or something similiar (just imagining at the moment). It all depends on the context really.
If you want to wait for a certain objective to be met, then create an event that fires once that objective is complete, and bind it to a function which runs the code you want to execute afterwards. Really I would need to see a specific example to give any sort of real answer.
If you can set up an event that will fire instead of using a loop, that would probably be the best.
To make it resume after X seconds, you would probably just manually resume it later if it wasn’t already resumed.