Random Room Generating Problem

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! :smiley:

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
2 Likes

I would assume it’s this line? You’re subtracting a Vector every time you create a new room, so in theory it’d make sense for it to only go in one direction.

Building off of that, it appears you’re only setting loc1, loc2, and loc3, to negative values. Which would mean, if I understood your code correctly, you’d always be getting a positive vector; never going back the other way.

Maybe you could randomly choose a negative or positive value on one of those axis? This is a bit hard to understand as I think this is only a portion of your code; I can’t really see the whole picture.

I’d be glad enough to send you the file, and maybe you could see what’s up with it! Beware tho, it’s pretty messy. :sweat_smile:

1 Like

Sure! No promises I can find anything, but I’ll give it a shot.

Haha, thanks! No worries though if you can’t find anything wrong with it!

I pulled this out from the game, so you may see some random leftover useless code. :sweat_smile:

((Moved It To DMs!))

1 Like