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

script timeout: exhausted allowed execution time?

Asked by 3 years ago

I have a room generation script, it sometimes doesnt have the error, and sometimes does, and im having trouble fixing it The thing is, when that happens, a huge or small part of rooms won't generate

local rooms = game.ReplicatedStorage:WaitForChild("Rooms"):GetChildren()


for i, placeHolder in pairs(game.Workspace.PlaceHolder:GetChildren()) do
        local chosenRoom = rooms[math.random(1,#rooms)]:Clone()
        chosenRoom.PrimaryPart = chosenRoom.Part
        local rotation = math.random(0,2)
        if rotation == 0 then
            chosenRoom:SetPrimaryPartCFrame(placeHolder.CFrame)
        elseif rotation == 1 then 
            chosenRoom:SetPrimaryPartCFrame(placeHolder.CFrame * CFrame.Angles(0,math.rad(-90),0))
        else 
            chosenRoom:SetPrimaryPartCFrame(placeHolder.CFrame * CFrame.Angles(0,math.rad(90),0))
        end

        placeHolder:Destroy()
        chosenRoom.Parent = game.Workspace
end

this is the code, if anyone can help, itd be appreciated, thanks.

1 answer

Log in to vote
1
Answered by 3 years ago

Your loop was running too many times per second put in a wait(1) in your loop so it doesnt break.

0
depending on how big the rooms are or if theres a lot of things in game.Workspace.PlaceHolder, you might want to make the cooldown between each room generation a bit longer or slowly generate the room instead of instantly cloning and moving it to workspace to reduce the lag BulletproofVast 1033 — 3y
0
putting wait(1) worked, thanks Sold50ChildrenToday 9 — 3y
0
np epicnmac 63 — 3y
0
bulletproofvasts explanation was better though epicnmac 63 — 3y
0
i appreciate both of you guys' answers Sold50ChildrenToday 9 — 3y
Ad

Answer this question