Does anyone know what that error is about? I looked it up but nothing really helps. It’s the one error that breaks a game I’m developing for overtime. I thought it could be that a function takes way too long to finish or it’s because of how I’m using spawn()? I’m not entirely sure. It’s apart of my round-based code in which I would rather not share. An explanation of this error would be appreciated.
You’ve probably encountered one of the protections that Roblox has in place for long running scripts. It occurs when a script runs longer than a predefined ‘timeout’ setting in seconds without yielding. When this happens, it usually causes the game to freeze for a couple seconds. Are you experiencing this freezing? If not, it is probably something else. If you are experiencing the freezing, then it is likely caused by an infinite loop without waits. In some cases you need to perform a heavy calculation which can take longer than the timeout. If this is the case, then I’d recommend adding some wait()'s at strategic locations and performing the calculation over a longer period of time.
Although I don’t think it is a good idea, You can call ScriptContext:SetTimeout() from the command line to manually change the maximum timeout for your game.
Thanks for the explanation but I’m not experiencing any freezing and I’ve asked other players and they say the game just breaks thats all. Could it be that the function is never ending because I’m calling a function in a function and then back again so it never completes? Not entirely sure. Thanks
Something like this:
function timer()
-- if new game:
newgame()
-- elseif move onto the next round:
gameplay()
end
function newgame()
-- do stuff
gameplay()
end
function gameplay()
-- do stuff
timer()
end
newgame()
If the game script timeout happens on the server then the server will freeze, but the client will keep running fine. As far as I’m aware, game script timeout
will only happen when a Lua script has been running for 20 seconds without yielding (which freezes whatever computer it’s running on). This limit is 10 seconds in Studio instead of the 20 it normally is online.
game script timeout
should be giving you a script and line number. That was the code that was running when it reached the 20 second limit. For some reason your game is likely getting stuck running that code over and over without yielding or running it for too long in general.
This will not affect the timeout for online as far as I’m aware. It will only affect the timeout for your Studio session.
When your users say, “the game just breaks,” what is actually happening? The game logic probably stops because an error was thrown. (btw, I’d wrap all of this in a pcall and provide a generic game state reset to band-aid similar issues.) Can they see other players move around, or other server side logic before this error is thrown? If not, then the server probably froze.
Yeah I think the server froze so I’m going to wrap some parts of my code into a pcall like you suggested because I don’t really know what is causing it to as I have no infinite loops or whatever. I try to avoid loops by using events. Thanks for the help though, it has helped me understand what is happening.
Thanks for the explanation as well. I do appreciate it.
What I know is, when you do a while true do
loop, it says, “Game script timeout”. You have to add wait() to not make it break.
I have never had a function run “too long” and I’ve had scripts that keep running the entire game session.
I am 99% sure that your script is infinitely looping through the functions you provided, because each one references each other with absolutely no waits, yields, or even code executed.
This is essentially, as @Enchanted_Tix described, a while true do loop that is never yielding or ending, thus causing the script to crash and consequently “timeout”.
Adding wait() is bad practice! Instead you should explore other options such as tick, runservice and etc.
Ukendio, how does the wait() function bad practice? Does it break the script line?
Wrong thread. That’s for regular wait. If you want a more specific topic regarding adding wait as the condition for a while loop, read this thread:
cc @Enchanted_Tix - It’s bad code. Read the above thread. There was also no need to necrobump this thread to include that tidbit.