Luau Scripting

Roblox Script Timeout Error: Fix Exhausted Execution Time

Why Roblox stops scripts with "Script timeout: exhausted allowed execution time", and how to fix it with yields, time budgets, and smaller chunks of work.

Roblox Script Timeout Error: Fix Exhausted Execution Time
On this page
  1. What “exhausted allowed execution time” actually means
  2. Fix 1: Add a yield to every pass of the loop
  3. Fix 2: Yield on a time budget for heavy loops
  4. Fix 3: Split one huge operation into smaller pieces
  5. Fix 4: Look for accidental infinite loops
  6. Can you raise or turn off the timeout?
  7. If it still doesn’t work
  8. Related guides
  9. Sources

The Roblox error “Script timeout: exhausted allowed execution time” means one of your scripts kept running without ever pausing, so the engine stopped it. Most of the time the cause is a loop with no yield in it. This guide shows how to find that loop and fix it, plus what to do when the work really is too heavy to finish in one go.

What “exhausted allowed execution time” actually means

Roblox runs a watchdog that keeps an eye on running scripts. According to the Creator Hub reference for ScriptContext:SetTimeout, the limit applies per resumption: if a thread runs longer than the allowed time since it was last resumed without yielding, the watchdog aborts it with this exact error.

Yielding means the script pauses and hands control back to the engine, for example with task.wait(), an event’s :Wait(), or a call like WaitForChild. The Creator Hub’s performance guide explains why this matters: Luau code runs synchronously and blocks the main thread until it hits something that yields. While your code is stuck in a long loop, nothing else that frame can run. That’s why Studio or the game often freezes for a few seconds before the error shows up.

So the error is not about how long your script has existed in total. A script can run all game long without issues, as long as it keeps pausing between chunks of work.

flowchart TD
    A["Open the line from the error"] --> B{"Is it a loop?"}
    B -->|"Yes"| C{"Yields on every pass?"}
    C -->|"No"| D["Add task.wait() to every path"]
    C -->|"Yes, still slow"| E["Yield on a time budget"]
    B -->|"No, one heavy call"| F["Split the work into chunks"]

Fix 1: Add a yield to every pass of the loop

The most common trigger is a while true do or repeat ... until loop that waits only some of the time. Here’s a typical broken version:

while true do
	if roundActive then
		checkRound()
		task.wait(1)
	end
end

When roundActive is true, the loop waits one second each pass and everything is fine. When it’s false, the if block is skipped, nothing yields, and the loop spins as fast as it can until the watchdog stops it.

Move the wait outside the condition so it runs no matter what:

while true do
	if roundActive then
		checkRound()
	end
	task.wait(1)
end
  • if roundActive then ... end only does the work when it’s needed.
  • task.wait(1) now runs on every pass, so the loop pauses for one second whether or not the round is active.

The same applies to repeat ... until loops that wait for a condition. A loop like repeat until door.Open never yields. Add task.wait() inside it, or better, listen for an event instead of polling (for example, a property changed signal on the object you’re waiting for).

Check continue and early break paths too

If your loop uses continue, every pass that jumps to continue skips the code below it, including a task.wait() placed at the bottom. Put the wait at the top of the loop body, or right before each continue, so no path can skip it.

Fix 2: Yield on a time budget for heavy loops

Sometimes you really do need to loop a lot: generating a map, processing a big table, running a pathfinding or search algorithm. Waiting a full step after every single iteration would make that very slow. Instead, do as much work as fits in a small time slice, then yield.

local BUDGET = 1 / 120 -- seconds of work before yielding
local sliceStart = os.clock()

for index, item in items do
	processItem(item)

	if os.clock() - sliceStart > BUDGET then
		task.wait()
		sliceStart = os.clock()
	end
end

Here’s what each part does:

  • BUDGET is how long the loop may run before it pauses. A small value like 1/120 of a second leaves time for the rest of the frame. Tune it for your game.
  • os.clock() returns elapsed time in seconds with high precision, which the Creator Hub recommends for measuring durations.
  • processItem(item) stands in for your own work for one item.
  • if os.clock() - sliceStart > BUDGET checks whether this slice has used up its time. If it has, task.wait() yields until the next step and the timer starts again.

This pattern was suggested on the Roblox DevForum for long-running search code, and it lines up with the Creator Hub’s own advice to break up large or expensive tasks with task.wait() so the work is spread across multiple frames.

Fix 3: Split one huge operation into smaller pieces

Not every timeout comes from a loop you wrote. A single heavy call can take long enough on its own. DevForum reports mention terrain operations on very large regions, such as copying the whole terrain at once, as one example.

The fix is the same idea at a bigger scale:

  1. Break the job into chunks (for example, smaller regions or batches of a few hundred items).
  2. Run one chunk at a time.
  3. Call task.wait() between chunks.

The Creator Hub also recommends spreading startup work across multiple frames instead of running it all at once, so this applies to large setup scripts that build a map or load content when a server starts.

Fix 4: Look for accidental infinite loops

If the loop is supposed to end but never does, adding a yield only turns a timeout into a script that runs forever in the background. Check for:

  • A while condition that can never become false, for example a counter you forgot to increase.
  • A repeat ... until condition that reads a value nothing ever changes.
  • A function that calls itself with no stopping case (recursion that never ends).

A quick way to find the culprit is to add a print inside the loop and watch the Output window, or set a breakpoint and step through it.

Can you raise or turn off the timeout?

In Studio, yes, but treat it as a debugging tool, not a fix.

OptionWhereWhat it does
Script Timeout LengthStudio Settings (search for it with Alt+S on Windows, ⌥S on Mac)Studio-side setting for how long a script can run before timing out
Studio.ScriptTimeoutLengthStudio class property (plugin security)The same setting, readable and writable by plugins
ScriptContext:SetTimeout(seconds)Plugin-security methodSets the watchdog limit; the reference says 0 disables it

None of these make slow code faster. A script that runs for many seconds without yielding still blocks everything else that frame, so players would see the same freeze. DevForum posters also report that disabling the timeout can lock up Studio for good if the loop really is infinite, so save your place before you experiment.

If it still doesn’t work

  • Check which script the error names. The Output message includes the script path and line number. If it points to a plugin, disable that plugin rather than editing your game.
  • Check other loops in the same script. The error appears where the thread was stopped, which is inside the loop that didn’t yield.
  • Watch out for DataStore or web calls in tight loops. Those yield, but sending too many too quickly causes other problems, like the DataStore “request was added to queue” warning.
  • Prefer events over polling. Replacing a while loop that checks for something with an event connection removes the loop entirely, which is often the cleanest fix. Similarly, if you’re waiting for an object to appear, use WaitForChild with a timeout instead of a spinning loop, as covered in the Infinite yield possible guide.

Test each change in a Studio playtest and keep an eye on the Output window. If the freeze goes away and the error stops appearing, your loop is yielding properly. As a final habit: every time you write while true do, add the task.wait() line before you write anything else inside it.

Sources

Frequently asked questions

What does "Script timeout: exhausted allowed execution time" mean?

A script ran for too long without yielding, so the engine's watchdog stopped it. The Creator Hub describes the limit as a per-resumption budget: the time a thread may run since it was last resumed without handing control back.

Does adding task.wait() fix the script timeout error?

Usually, yes. A task.wait() call yields the thread and resumes it on a later step, which resets the time the thread has been running. It has to be on every path through the loop, not only inside one if branch.

Can I just turn off the script timeout in Roblox Studio?

Studio has a Script Timeout Length setting, and plugins can call ScriptContext:SetTimeout, but these change Studio behavior only. They hide the problem instead of fixing it, and a script that blocks for that long also freezes everything else that needs to run.

Why does my game freeze before the error appears?

Luau runs synchronously and blocks the main thread until it hits a yield. While your loop runs without yielding, nothing else in that frame can run, so Studio or the client appears frozen until the watchdog stops the script.

Related guides