Game Script Timeout


#1

In my game, players are able to save and load their builds. It does this by converting the player’s build into a string and storing it for later use. When it loads the string back into an instance, it takes about 30 seconds or so depending on the size of the player’s build. Please note that the loading/saving script has remained untouched for about a few months now and has worked fine up until last Thursday (July 5th) when this error started popping up:

image

which leaves me to believe that a Roblox update may have caused this. I understand this error is happening because the loop in the loading script goes on for awhile without yielding and has no waits in between, but if I add waits to the process, then loading player’s builds could take up to 10 minutes!

According to this:
https://wiki.roblox.com/index.php?title=API:Class/ScriptContext/SetTimeout
I should be able to set how long a script can run without yielding, and so I have tried setting the timeout to 2 minutes in the command bar but doing so has had no effect and the error still occurs.


#2

You should change your code so that the script isn’t hanging for 30 seconds to save data. I think it’s fair that the system is terminating the script for 30 seconds of no response. Maybe throw in some waits in there and see if that helps?


#3

This is not a recent update, scripts have had timeouts for at least 5 years.

One aspect to consider with scripts is that when a script is running, no other work (including no other scripts) happens in parallel, except for some rendering work that happens in parallel with everything. This means that when your script takes 30 seconds to build this data:

  • if this is happening on the server, the server is not sending network updates to anyone: everyone in the server is getting network lag
  • if this is happening on the client, up to 1 frame renders over the course of that 30 seconds

Because of these properties, it is strongly recommended that you add wait() or other calls to yield your script to improve the game experience for all of your users.


#4

I’ve managed to add waits to the process without making loading times too lengthy, and it seems to have stopped the error from occurring.

But what I don’t understand is… why would I start getting the timeout error now after a year of it working perfectly fine? I know that script timeouts have been around for awhile, but I’m wondering if Roblox might have changed the default script timeout during a recent update or something along those lines. It doesn’t make sense for the script to suddenly encounter this error after going for so long without any issues.

And why would it be that SetTimeout has had no effect whatsoever?


#5

ScriptContext:SetTimeout only adjusts the timeout for your current session, the timeout value is not saved with the file. We allow modification of the value in studio because sometimes you need extremely long timeout values for offline world generation scripts and other edit-time scripting.

The timeout is a threshold, so it is possible that your scripts previously were taking, e.g., 28 seconds to complete, and through some small change they now take slightly longer than 30 seconds. This roblox wiki page has some information regarding how to measure which scripts are taking time: http://robloxdev.com/articles/MicroProfiler . Often performance bottlenecks are not obvious, so empirically measuring it can help.


#6

Ahhh, thank you, that makes a lot more sense! Sorry for the trouble!