Room Generator help

Hello, I’m having trouble with generating rooms. This is the script:

local room = {}
room.random = Random.new()

function room.Generate(prevRoom)
	local possibleRooms = workspace.Rooms:GetChildren()
	local randomRoom = possibleRooms[room.random:NextInteger(1, #possibleRooms)]
	local newRoom = workspace.Rooms.LongTurnow
	newRoom = randomRoom:Clone()
	
	newRoom.PrimaryPart = newRoom.Entrance
	newRoom:PivotTo(prevRoom.Exit.CFrame)
	
	newRoom.Parent = workspace.GeneratedRooms
	
	return newRoom
end

return room

Rooms are generating like this:
image
On top of eachother, inside of eachother…

There are literally no corners in the set of rooms and I have absolutely no idea why it’s doing this.

Any help would be nice! :slight_smile:

Here is the server script:

local room = require(script.Room)

local prevRoom = workspace.StartRoom

for i=1, 100 do
	prevRoom = room.Generate(prevRoom)
end
1 Like