Help Needed for a Procedurally Generated Room System

So I’ve been trying to make a game like Lethal Company which utilizes a randomly procedural room generation system. Basically a house with a lot of randomly generated rooms including dead ends and forks. I’ve been cracking out at this for a while today and the rooms just overlap and are messy.
image

Here’s one of my room models; it has a start and end part with the primarypart of the model being the start part. It also has another model inside it for the hitboxes of the room.


Some rooms like this one have multiple EndParts to continue generating the room from a random one of those parts, and the hitbox for the room looks like this:

Now I’ve done the scripting trying to keep it simple, as forks have not been added, and the failed attempt at room collision detection is in there, but the code still doesn’t work at all. Here’s the script:

local RoomsFolder = game.ReplicatedStorage.Rooms

local HouseFolder = game.Workspace.House
local RoomGenerations = 20

local RoomGenerationBegin = game.Workspace.RoomGenerationBegin
local lastGenerationCFrame
for i = 1, RoomGenerations do
	local newRoom
	if i == 1 then
		newRoom = RoomsFolder:GetChildren()[math.random(1, #RoomsFolder:GetChildren())]:Clone()
		newRoom:PivotTo(RoomGenerationBegin.CFrame)
	else
		local shuffledRooms = {}
		for i, v in RoomsFolder:GetChildren() do
			local randomIndex = math.random(1, #shuffledRooms + 1)
			table.insert(shuffledRooms, randomIndex, v)
		end
		local currentRoom
		local colliding = true
		while colliding == true do
			for i, v in pairs(shuffledRooms) do
				local hitboxGroup = v.Hitbox
				local collided = false
				for i, v: BasePart in pairs(hitboxGroup:GetChildren()) do
					local partsInHitboxPart = workspace:GetPartBoundsInBox(v.CFrame, v.Size)
					for i, v: BasePart in partsInHitboxPart do
						if v.Parent.Name == "Hitbox" and v.Parent ~= hitboxGroup then
							collided = true
							print("collided")
							break
						end
					end
				end
				if collided then
					table.remove(shuffledRooms, i)
				else
					currentRoom = v
					colliding = false
					break
				end
			end
			newRoom = currentRoom:Clone()
			newRoom.Parent = game.Workspace
			newRoom:PivotTo(lastGenerationCFrame)
		end
	end
	newRoom.Parent = HouseFolder
	local endParts = {}
	for i, v in newRoom:GetChildren() do
		if v.Name == "EndPart" then
			v.Transparency = 1
			table.insert(endParts, v)
		end
		if v.Name == "StartPart" then
			v.Transparency = 1
		end
	end

	local randomEndPart = endParts[math.random(1, #endParts)]
	lastGenerationCFrame = randomEndPart.CFrame
end

Please help me I wanna make this this game happen. What am I doing wrong and how do I add things like forks and allat?

You might wanna add a condition where if the next room overlaps with a previous room, This should be done with some grid-like room placement. In the image, the grid cannot be described so I would suggest making every room the maximum size of atleast 50 studs. If you don’t want that then you can do that on your own way. You can also make use of raycast to determine what room should be generated to avoid the overlapping issue.