I’ve been experimenting around with random room(s) generating, and honestly, it’s my first time messing around with these, so my code might not be the best out there. I quickly put together a code, and I can’t seem to figure out what’s wrong here?

Based on the picture (below), the map is being generated, but the rooms are only being generated one direction, and not the other. Any clue on to why it’s acting like that?

Code:

```
local rooms = game.ReplicatedStorage:WaitForChild("Rooms")
local LastRoom
local CurrentRoom
local loc1 = -100
local loc2 = 0
local loc3 = 0
function createRoom(num)
local WorldChosen = rooms:FindFirstChild('World'..num):GetChildren()
local RoomChosen = WorldChosen[math.random(1,#WorldChosen)]:Clone()
RoomChosen:SetPrimaryPartCFrame(LastRoom.PrimaryPart.CFrame - Vector3.new(loc1,loc2,loc3))
RoomChosen.Parent = workspace.RoomHolder
LastRoom = RoomChosen
if RoomChosen.Name == 'Room1' or RoomChosen.Name == 'Room5' or RoomChosen.Name == 'Room6' then
if loc1 == -100 then
LastRoom:SetPrimaryPartCFrame(CFrame.new(RoomChosen.PrimaryPart.Position) * CFrame.Angles(0,math.rad(RoomChosen.Settings.AngleY.Value),0))
elseif loc3 == -100 then
LastRoom:SetPrimaryPartCFrame(CFrame.new(RoomChosen.PrimaryPart.Position) * CFrame.Angles(0,math.rad(RoomChosen.Settings.AngleZ.Value),0))
end
elseif RoomChosen.Name == 'Room2' or RoomChosen.Name == 'Room4' then
if loc1 == -100 then
LastRoom:SetPrimaryPartCFrame(CFrame.new(RoomChosen.PrimaryPart.Position) * CFrame.Angles(0,math.rad(RoomChosen.Settings.AngleZ.Value),0))
loc1 = 0
loc2 = 0
loc3 = -100
elseif loc3 == -100 then
LastRoom:SetPrimaryPartCFrame(CFrame.new(RoomChosen.PrimaryPart.Position) * CFrame.Angles(0,math.rad(RoomChosen.Settings.AngleY.Value),0))
loc1 = -100
loc2 = 0
loc3 = 0
end
elseif RoomChosen.Name == 'Room3' then
if loc1 == -100 then
LastRoom:SetPrimaryPartCFrame(CFrame.new(RoomChosen.PrimaryPart.Position) * CFrame.Angles(0,math.rad(RoomChosen.Settings.AngleZ.Value),0))
loc1 = 0
loc2 = 0
loc3 = -100
elseif loc3 == -100 then
LastRoom:SetPrimaryPartCFrame(CFrame.new(RoomChosen.PrimaryPart.Position) * CFrame.Angles(0,math.rad(RoomChosen.Settings.AngleY.Value),0))
loc1 = -100
loc2 = 0
loc3 = 0
end
end
RoomChosen.CameraPart.Rotation = Vector3.new(0,-180,0)
end
```

(Btw, I’m running and looping this function)

Any help is needed! Thanks!