For a bit now, I’ve been messing around on something new (that I haven’t tackled on yet) and plan to use this method on an upcoming side project.
I put together a quick test code, and can’t seem to get it to work as intended. Based on the picture (below), the map is being generated, but the rooms are only being generated one direction, and not the other.
What I’m saying here is that I wanted the rooms to not all generate in one line, but instead, branch out. But based on the picture, you can see that the rooms are all in one line instead of branching out.
Any clue as to why? I would prefer to speak on discord if you think you might have a full out solution.
All help is needed, Thanks!
Picture:
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