In short
Scripts in Roblox share one thread with the game: while your code runs, nothing else does. A loop that never pauses freezes everything, so after a few seconds Roblox stops the script with this error. Find the loop on the line it names, and make it yield every pass with task.wait(), or give it a condition that ends it.
- Before the error, Studio usually freezes for a few seconds. That freeze is the loop running.
- A
while true doloop always needs atask.wait()inside it.
What the message means
ServerScriptService.Spawner:5: Script timeout: exhausted allowed execution time
Other forms of the same message:
Script timeout: exhausted allowed execution time for the current resumption point
Roblox only takes control back when a script yields: task.wait, an event's :Wait(), a WaitForChild that has to wait, and so on. Code that never yields keeps the thread forever, so the engine has a watchdog that ends it.
The line in the message is where the script was when time ran out, which is inside the loop that never yielded.
Causes and fixes
Three things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.
A loop with no task.wait
The classic: a while true do loop that checks or moves something, with no wait inside. It runs millions of times without ever letting the game draw a frame.
local part = workspace:WaitForChild("Spinner")
while true do
-- no wait: Script timeout: exhausted allowed execution time
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(1), 0)
end
Yield on every pass. For something that should move every frame, connect to RunService.Heartbeat instead of a loop.
local RunService = game:GetService("RunService")
local part = workspace:WaitForChild("Spinner") :: BasePart
local DEGREES_PER_SECOND = 90
RunService.Heartbeat:Connect(function(dt: number)
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(DEGREES_PER_SECOND * dt), 0)
end)
A loop waits for something without yielding
A repeat ... until or while that waits for a value to change, but never pauses, never gives the rest of the game a chance to change it.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local roundActive = ReplicatedStorage:WaitForChild("RoundActive")
-- nothing else can run while this spins, so the value never changes
repeat
until roundActive.Value == true
print("round started")
Wait for the change with the value's event, or put task.wait() in the loop.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local roundActive = ReplicatedStorage:WaitForChild("RoundActive") :: BoolValue
while not roundActive.Value do
roundActive.Changed:Wait()
end
print("round started")
Too much work in one go
Generating a big map, cloning thousands of parts or looping over every descendant of Workspace in one go can take longer than the limit, even though the loop does end.
local template = Instance.new("Part")
template.Anchored = true
template.Size = Vector3.new(4, 1, 4)
-- a quarter of a million parts in one go can run past the limit
for x = 1, 500 do
for z = 1, 500 do
local tile = template:Clone()
tile.Position = Vector3.new(x * 4, 0, z * 4)
tile.Parent = workspace
end
end
Split the work and yield between batches, so the game keeps running while it builds. Also ask whether you really need that many parts.
local template = Instance.new("Part")
template.Anchored = true
template.Size = Vector3.new(4, 1, 4)
local SIZE = 100
for x = 1, SIZE do
for z = 1, SIZE do
local tile = template:Clone()
tile.Position = Vector3.new(x * 4, 0, z * 4)
tile.Parent = workspace
end
task.wait() -- one row per frame
end
Fix it in your place
Paste the error, RoCode fixes it in your place
Copy the line from Output and paste it here. RoCode opens the script it names in the place you have open in Studio, works out which of the causes above it is, and edits the code there instead of handing you a snippet to paste.
RoCode is an AI agent for Roblox Studio: it reads the scripts in the place you have open, finds the line and edits it there, and every change is an undo point. It runs on Windows or macOS with a desktop browser. Free to start, with free credits every day.
How to find the line that causes it
- Open Output (Window menu, or the Script tab), clear it with Ctrl+K (⌘K on Mac), and press Play.
- Find the first red line. It starts with the script's place in the Explorer and the line number, such as
ServerScriptService.Shop:12:. - Click the red line. Studio opens that script with the cursor on the failing line.
- Read the lines between
Stack BeginandStack Endunder it: they list the calls that led there, newest first, so you can see which function called the broken one. - Still not sure which value is wrong? Add
print(typeof(x), x)just above the line, or set a breakpoint on it and read the values in the Watch window.
Questions
Why does Studio freeze before the error?
The loop is using the only thread the game has, so Studio cannot draw or respond until the loop is stopped. The error is Roblox stopping it.
Is wait() enough, or should I use task.wait()?
Use task.wait(). It is the current version and resumes on the next frame without the throttling the old wait() had.
Can I raise the time limit?
Studio has a Script Timeout setting, but raising it only hides the problem: players still get a frozen game. Make the loop yield instead.
Can RoCode fix it?
Yes. Paste the Output line into RoCode. It finds the loop in the script in your open place and adds the wait, the event, or the batching it needs.
Sources and further reading
- Roblox Creator Docs: task.wait
- Roblox Creator Docs: RunService.Heartbeat
- Roblox DevForum: Script timeout: exhausted allowed execution time
- Roblox DevForum: "Script timeout: exhausted" on almost all my scripts
How the code was checked: every block marked Fixed passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 23 October 2026), and every block marked Breaks compiles and fails only when it runs. The message wording was checked against the message strings in Roblox Studio itself (macOS build of 13 October 2026) on 23 October 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.