Reputation: 1
I am getting the folowing error when running my script:
Script timeout: exhausted allowed execution time
Here is my script:
-- Define variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local Status = ReplicatedStorage:WaitForChild("Status")
local GameLength = 55
local reward = 25
-- Game loop
while true do
-- <game loop body here>
end
Why is this happening and how can I fix it?
Upvotes: 0
Views: 527
Reputation: 69
U missing a wait in ur while loop, this causes to overflow the server/client.
Upvotes: 0
Reputation: 7188
As ewong was hinting at in the comments, your issue is with the line while true do end
. It's unclear from your code sample why you are doing this, but I'll assume that when you said that this isn't the full code, that you removed the contents of the loop itself.
In an engine like Roblox, each script has a limited amount of time to complete its work before the engine needs to move on. If it cannot finish the work, and never yields, then the engine will kill it to prevent it from locking up the rest of the game.
The most simple fix to make this error go away is to allow your loop to yield. So adding wait()
inside the loop will do the trick.
while true do
-- do your game logic every tick here
wait()
end
However, the better way to have code execute every tick is to listen to the RunService.Heartbeat signal.
game.RunService.Heartbeat:Connect( function(timeStep)
-- do your game logic here
end)
Upvotes: 1