Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

script timeout: exhausted allowed execution time?

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

✓ Accepted answer

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

5 comments

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

0

putting wait(1) worked, thanks

0

np

0

bulletproofvasts explanation was better though

0

i appreciate both of you guys' answers

This discussion is preserved as it was. New answers, comments, and votes are closed.