Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] How do I fix this error, "Script timeout: exhausted allowed execution time?"

Asked by 3 years ago
Edited 3 years ago

THIS QUESTION HAS BEEN SOLVED

Information:

  • I am getting an error on line 5. The error is "Script timeout: exhausted allowed execution time"
  • I am trying to do a coin spawning script
  • I want to spawn 5 coins when no coins can be found in game.Workspace.Coins
  • I am cloning from game.ReplicatedStorage.Coins
  • The name of the coins are "Coin"

Script:

while true do
    local c = game.Workspace.Coins:FindFirstChild("Coin")
    if not c then
        wait()
            for i,coin in pairs(game.ReplicatedStorage.Coins:GetChildren()) do
                local clone = coin:Clone()
            clone.Parent = game.Workspace.Coins
        end
    end
end
0
when doing while true do you need a wait() that will always happen botw_legend 502 — 3y

2 answers

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
3 years ago

Same concept as the other answer, but here is an even simpler way to do this (I also would not recommend while true loops, but for some things it's ok):

while wait() do --just have the wait in the condition and it will wait then loop. Its quick and easy while also not breaking anything.
    local c = game.Workspace.Coins:FindFirstChild("Coin")
    if not c then
            for i,coin in pairs(game.ReplicatedStorage.Coins:GetChildren()) do
                local clone = coin:Clone()
            clone.Parent = game.Workspace.Coins
        end
    end
end
0
Works perfectly! Dave_Robertson 42 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

You need to add a wait() so that your script does't get over whelmed. Basically your code is running too many times a second, and this causes an error so that Roblox Studio doesn't crash. Even if it is a 0.5 second wait that will stop your code from running hundreds of times ever second. Here is what your code should look like now:

while true do
    local c = game.Workspace.Coins:FindFirstChild("Coin")
    if not c then
        wait()
            for i,coin in pairs(game.ReplicatedStorage.Coins:GetChildren()) do
                local clone = coin:Clone()
        wait(--time to wait)
            clone.Parent = game.Workspace.Coins
        end
    end
end

If this does help you make sure to accept my answer. Good luck with your project.

Answer this question