Are long waits safe?

I encountered a rare bug in one of my games which changes map every 3 minutes, using a 180 second wait.
The script that changes the map had apparently stopped with no errors.
Is it possible for long-inactive threads to simply be terminated?

It’s most likely erroring, are you pcalling but not outputting the error? it shouldn’t terminate at all unless you stop it for some reason.

2 Likes

There’s at least one silent pcall (silent because it handles errors that are unavoidable and unimportant), but nothing that can terminate the main loop.

1 Like

wait(180) shouldn’t terminate the thread.

I’d recommend adding prints to each step of the loop, and narrow down where it stops.

so like

while wait(1) do
print("Step 1")
-- more code
print("Step 2")
for i=1,1000 do
--example for loop
end
print("Step 3")
end
2 Likes

You could possibly get better feedback and reliability if you create a coroutine for your 3-minute timer, rather than just using wait() in the Script itself. If the coroutine just waits and calls a pcall’d function, or fires an Event, it should keep going forever even if the code it’s trying to periodically execute errors for some reason, since it’s either pcall’d or not in the same thread. Coroutines also have a status propertly, so you can add code to explicitly check if the thread is running (from an admin command, for example) for diagnostic purposes.

2 Likes

I added a couple of diagnostic prints.
Hopefully this will explain whether the reason the playercount of the affected game drops to zero because it breaks, drops to zero because people realise there’s only 8 different maps, or drops to zero because of extremely toxic behaviour.