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.

5 comments
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
putting wait(1) worked, thanks
np
bulletproofvasts explanation was better though
i appreciate both of you guys' answers