I need help scripting infinitely generated rooms

I have been trying to make a game that infinitely generates rooms. I’ve looked online and the only thing I could find was this script.

Here is the script:
local rooms = game.ReplicatedStorage:WaitForChild(“GeneratedRooms”):GetChildren()

for i, placeHolder in pairs(game.Workspace.PlaceHolders:GetChildren()) do
local chosenRoom = rooms[math.random(1,#rooms)]:Clone()
chosenRoom.PrimaryPart = chosenRoom.Floor
chosenRoom:SetPrimaryPartCFrame(placeHolder.CFrame)

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

Here is how this script works:


This is what it looks like before the script is run


This is what happens when I run the script

What I am trying to do is modify this script to make it go infinitely. I would appreciate any help.

2 Likes

First of all this is not how games achieve an infinite spawn. You can’t just infinitely spawn rooms all at once. You need a trigger let’s say,

You start with 3 rooms, then when you get pass the 1st room it deletes/destroys the 1st room and adds a new room to the end.

2 Likes