Help with dungeon generation

I have been working on a dungeon generation system, and most of the time some of the rooms miss-place.

Here are some of the images that show problems:

The first one shows the rooms leaving an empty corner.

The second one shows a room miss-placed.

This is the generation script inside of (ServerScriptService):

local PathFindService = game:GetService("PathfindingService")

local Generated = Instance.new("Folder", workspace)
Generated.Name = "Generated"

local Rooms = game.ReplicatedStorage.Rooms:GetChildren()

for I, V in pairs(workspace.Grid:GetChildren()) do
	
	if V:IsA("Model") then
		
		-- None
		
	else
		
		V.Transparency = 1

	end

	
end

for I, V in pairs(Rooms) do
	
	V.PrimaryPart = V.Floor	
	
end

local Rotations = {0, 90, 180, 270} -- Rotations for the rooms

local function Generate()
	
	Generated:ClearAllChildren()
	
	for I, V in pairs(workspace:FindFirstChild("Grid"):GetChildren()) do
		
		if V:IsA("Model") then
			
			-- None
			
		else
			
			local ChosenRoom = Rooms[math.random(1, #Rooms)]:Clone()
			ChosenRoom:SetPrimaryPartCFrame(V.CFrame * CFrame.Angles(0, math.rad(Rotations[math.random(1, #Rotations)]), 0))
			ChosenRoom.Parent = Generated
			
		end
		
	end
	
end

wait(3)

local Path

repeat wait()
	
	Generate()
	
	Path = PathFindService:CreatePath()
	Path:ComputeAsync(workspace.Grid.Start.Floor.Position, workspace.Grid.End.Floor.Position)
	
until Path.Status == Enum.PathStatus.Success

Here are some images of the properties I’m using right now:

The first one is the floor. This is where the rooms will spawn.

image

The second one is the wall. The Y is the height of the walls.

image

If anyone knows how to help, let me know! :blush:

If the bases are joint perfectly its your building that needs adjustment to be universally joinable from each angle

I think it is correct and that you might be getting confused by if you want the walls to be inset or outset. Right now, it looks like grey models are hallways, and red are T or X which you would want to consider adding little corner pieces to make the walls of hallways it connects feel continuous.

I think you’ll need to share more about what is wrong, what you are expecting, and possibly the placefile if you want help further.