Most walls are being generated but some aren’t… idk how to fix that
local RS = game:GetService("ReplicatedStorage")
local Platforms = RS:WaitForChild("Platforms")
local DefaultPlatform = Platforms:WaitForChild("Default")
local PlatformsFolder = Instance.new("Folder", workspace)
PlatformsFolder.Name = "Platforms"
local MainRoomFolder = Instance.new("Folder", PlatformsFolder)
MainRoomFolder.Name = "MainRoom"
local RoomsFolder = Instance.new("Folder", PlatformsFolder)
RoomsFolder.Name = "Rooms"
local HallsFolder = Instance.new("Folder", PlatformsFolder)
HallsFolder.Name = "Halls"
local WallsFolder = Instance.new("Folder", workspace)
WallsFolder.Name = "Walls"
-- In RoomInfo, you can adjust somethings on generation
local RoomInfo = {
["RoomNumber"] = math.random(7, 10), -- How many rooms are there
["MainRoomSizeX"] = math.random(3,6), -- The X number of platforms that MainRoom will have
["MainRoomSizeZ"] = math.random(3,6), -- The Y number of platforms that MainRoom will have
["InitialPosition"] = Vector3.new(0,0,0), -- The initial position of it (the first main room platform will spawn at this coordinates)
["HallsMinSize"] = 3, -- The min size that a corridor must have
["HallsMaxSize"] = 6, -- The max size that a corridor must have
}
local function SetBridgeables(parent, sizeX)
for _, Platform: Part in pairs(parent:GetChildren()) do
Platform:SetAttribute("BridgeableUp", true)
Platform:SetAttribute("BridgeableRight", true)
Platform:SetAttribute("BridgeableLeft", true)
Platform:SetAttribute("BridgeableDown", true)
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = PlatformsFolder:GetChildren()
RayParams.FilterType = Enum.RaycastFilterType.Include
local RaycastTest1 = workspace:Raycast(Platform.Position + Vector3.new(0, 100, 20), Vector3.new(0,-10000,0), RayParams)
local RaycastTest2 = workspace:Raycast(Platform.Position + Vector3.new(-20, 100, 0), Vector3.new(0,-10000,0), RayParams)
local RaycastTest3 = workspace:Raycast(Platform.Position + Vector3.new(20, 100, 0), Vector3.new(0,-10000,0), RayParams)
local RaycastTest4 = workspace:Raycast(Platform.Position + Vector3.new(0, 100, -20), Vector3.new(0,-10000,0), RayParams)
if RaycastTest1 then
Platform:SetAttribute("BridgeableUp", false)
end
if RaycastTest2 then
Platform:SetAttribute("BridgeableRight", false)
end
if RaycastTest3 then
Platform:SetAttribute("BridgeableLeft", false)
end
if RaycastTest4 then
Platform:SetAttribute("BridgeableDown", false)
end
end
end
local function DesignAHallPlan(size, initialPosition, direction, timesTrying)
local hall = {}
local nowPosition = initialPosition
local myDirection = direction
for i = 1,size,1 do
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = PlatformsFolder:GetChildren()
RayParams.FilterType = Enum.RaycastFilterType.Include
local RaycastTest = workspace:Raycast(nowPosition + (myDirection * 20) + Vector3.new(0,100,0), Vector3.new(0,-10000,0), RayParams)
if not RaycastTest then
nowPosition = nowPosition + (myDirection * 20)
table.insert(hall, nowPosition)
if math.random(1,4) == 1 and i > 2 then
if myDirection.X ~= 0 then
if math.random(1,2) == 1 then
myDirection = Vector3.new(0,0,1)
else
myDirection = Vector3.new(0,0,-1)
end
else
if math.random(1,2) == 1 then
myDirection = Vector3.new(1,0,0)
else
myDirection = Vector3.new(-1,0,0)
end
end
end
else
if not timesTrying then
return DesignAHallPlan(size, initialPosition, direction, 1)
else
if timesTrying > 20 then
return nil
else
return DesignAHallPlan(size, initialPosition, direction, timesTrying + 1)
end
end
end
end
return hall, myDirection
end
local function GenerateRoom(lastBridge, direction, parent, timesTrying)
local myDirection = direction
local SizeX = math.random(4,7)
local SizeZ = math.random(4,7)
local InitialPosition = lastBridge.Position + (myDirection * 20)
local preventMultiplier = 1
if direction == Vector3.new(-1,0,0) or direction == Vector3.new(0,0,-1) then
preventMultiplier = -1
end
for x = 1, SizeX, 1 do
for z = 1, SizeZ, 1 do
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = PlatformsFolder:GetChildren()
RayParams.FilterType = Enum.RaycastFilterType.Include
local RaycastTest = workspace:Raycast(InitialPosition + Vector3.new((x-1)*20*preventMultiplier,0,(z-1)*20*preventMultiplier) + Vector3.new(0,100,0), Vector3.new(0,-10000,0), RayParams)
if RaycastTest then
for _, v in pairs(parent:GetChildren()) do
game:GetService("Debris"):AddItem(v, 0)
end
if not timesTrying then
return GenerateRoom(lastBridge, direction, parent, 1)
else
if timesTrying > 20 then
return nil
else
return GenerateRoom(lastBridge, direction, parent, timesTrying+1)
end
end
end
local Platform = DefaultPlatform:Clone()
local PlatformID = x + ((z-1)*SizeX)
Platform.Parent = parent
Platform.Name = "Platform"..PlatformID
Platform.Color = Color3.fromRGB(49, 176, 255)
Platform.Position = InitialPosition + Vector3.new((x-1)*20*preventMultiplier,0,(z-1)*20*preventMultiplier)
end
end
return SizeX
end
local function GenerateRoomProcess(roomFolder, roomType)
if roomType == "FirstRoom" then
local BridgeSize = math.random(RoomInfo["HallsMinSize"],RoomInfo["HallsMaxSize"])
local BridgeablesParts = {}
for _, v in pairs(MainRoomFolder:GetChildren()) do
local canInsert = false
if v:GetAttribute("BridgeableUp") then
canInsert = true
elseif v:GetAttribute("BridgeableLeft") then
canInsert = true
elseif v:GetAttribute("BridgeableRight") then
canInsert = true
elseif v:GetAttribute("BridgeableDown") then
canInsert = true
end
if canInsert then
table.insert(BridgeablesParts, v)
end
end
local myPart = BridgeablesParts[math.random(1,#BridgeablesParts)]
local Directions = {}
if myPart:GetAttribute("BridgeableUp") then
table.insert(Directions, "Up")
end
if myPart:GetAttribute("BridgeableLeft") then
table.insert(Directions, "Left")
end
if myPart:GetAttribute("BridgeableRight") then
table.insert(Directions, "Right")
end
if myPart:GetAttribute("BridgeableDown") then
table.insert(Directions, "Down")
end
local myDirection = Directions[math.random(1, #Directions)]
myPart:SetAttribute("Bridgeable"..myDirection, false)
local vectorDirection = Vector3.new(0,0,0)
if myDirection == "Up" then
vectorDirection = Vector3.new(0,0,1)
elseif myDirection == "Left" then
vectorDirection = Vector3.new(1,0,0)
elseif myDirection == "Right" then
vectorDirection = Vector3.new(-1,0,0)
elseif myDirection == "Down" then
vectorDirection = Vector3.new(0,0,-1)
end
local HallPlan = DesignAHallPlan(BridgeSize, myPart.Position, vectorDirection)
local LastBridge = nil
local BridgeParts = {}
if not HallPlan then
myPart:SetAttribute("Bridgeable"..myDirection, true)
return GenerateRoomProcess(roomFolder, roomType)
end
for i, v in pairs(HallPlan) do
local Platform = DefaultPlatform:Clone()
Platform.Parent = HallsFolder
Platform.Name = "Hall"..i
Platform.Position = v
Platform.Color = Color3.fromRGB(80,80,80)
table.insert(BridgeParts, Platform)
if i == #HallPlan then
LastBridge = Platform
end
end
--SetBridgeables(HallsFolder, 1)
local RoomSizeX = GenerateRoom(LastBridge, vectorDirection, roomFolder)
if RoomSizeX then
SetBridgeables(roomFolder, RoomSizeX)
for _, v in pairs(roomFolder:GetDescendants()) do
local everythingFine = true
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = PlatformsFolder:GetChildren()
RayParams.FilterType = Enum.RaycastFilterType.Include
local UpRaycastTest = workspace:Raycast(v.Position + Vector3.new(0,100,20), Vector3.new(0,-10000,0), RayParams)
local RightRaycastTest = workspace:Raycast(v.Position + Vector3.new(-20,100,0), Vector3.new(0,-10000,0), RayParams)
local LeftRaycastTest = workspace:Raycast(v.Position + Vector3.new(20,100,0), Vector3.new(0,-10000,0), RayParams)
local DownRaycastTest = workspace:Raycast(v.Position + Vector3.new(0,100,-20), Vector3.new(0,-10000,0), RayParams)
if UpRaycastTest and UpRaycastTest.Instance.Parent ~= roomFolder and UpRaycastTest.Instance.Parent ~= HallsFolder then
everythingFine = false
end
if LeftRaycastTest and LeftRaycastTest.Instance.Parent ~= roomFolder and LeftRaycastTest.Instance.Parent ~= HallsFolder then
everythingFine = false
end
if RightRaycastTest and RightRaycastTest.Instance.Parent ~= roomFolder and RightRaycastTest.Instance.Parent ~= HallsFolder then
everythingFine = false
end
if DownRaycastTest and DownRaycastTest.Instance.Parent ~= roomFolder and DownRaycastTest.Instance.Parent ~= HallsFolder then
everythingFine = false
end
if not everythingFine then
myPart:SetAttribute("Bridgeable"..myDirection, true)
for _, v in pairs(BridgeParts) do
game:GetService("Debris"):AddItem(v, 0)
end
return GenerateRoomProcess(roomFolder, roomType)
end
end
else
myPart:SetAttribute("Bridgeable"..myDirection, true)
for _, v in pairs(BridgeParts) do
game:GetService("Debris"):AddItem(v, 0)
end
return GenerateRoomProcess(roomFolder, roomType)
end
else
local BridgeSize = math.random(RoomInfo["HallsMinSize"],RoomInfo["HallsMaxSize"])
local BridgeablesParts = {}
for _, v in pairs(MainRoomFolder:GetDescendants()) do
local canInsert = false
if v:GetAttribute("BridgeableUp") then
canInsert = true
elseif v:GetAttribute("BridgeableLeft") then
canInsert = true
elseif v:GetAttribute("BridgeableRight") then
canInsert = true
elseif v:GetAttribute("BridgeableDown") then
canInsert = true
end
if canInsert then
table.insert(BridgeablesParts, v)
end
end
if math.random(1,15) == 1 then
for _, v in pairs(RoomsFolder:GetDescendants()) do
local canInsert = false
if v:GetAttribute("BridgeableUp") then
canInsert = true
elseif v:GetAttribute("BridgeableLeft") then
canInsert = true
elseif v:GetAttribute("BridgeableRight") then
canInsert = true
elseif v:GetAttribute("BridgeableDown") then
canInsert = true
end
if canInsert then
table.insert(BridgeablesParts, v)
end
end
end
local myPart = BridgeablesParts[math.random(1,#BridgeablesParts)]
local Directions = {}
if myPart:GetAttribute("BridgeableUp") then
table.insert(Directions, "Up")
end
if myPart:GetAttribute("BridgeableLeft") then
table.insert(Directions, "Left")
end
if myPart:GetAttribute("BridgeableRight") then
table.insert(Directions, "Right")
end
if myPart:GetAttribute("BridgeableDown") then
table.insert(Directions, "Down")
end
local myDirection = Directions[math.random(1, #Directions)]
myPart:SetAttribute("Bridgeable"..myDirection, false)
local vectorDirection = Vector3.new(0,0,0)
if myDirection == "Up" then
vectorDirection = Vector3.new(0,0,1)
elseif myDirection == "Left" then
vectorDirection = Vector3.new(1,0,0)
elseif myDirection == "Right" then
vectorDirection = Vector3.new(-1,0,0)
elseif myDirection == "Down" then
vectorDirection = Vector3.new(0,0,-1)
end
local HallPlan, finalDirection = DesignAHallPlan(BridgeSize, myPart.Position, vectorDirection)
local LastBridge = nil
local BridgeParts = {}
if not HallPlan then
myPart:SetAttribute("Bridgeable"..myDirection, true)
return GenerateRoomProcess(roomFolder, roomType)
end
for i, v in pairs(HallPlan) do
local Platform = DefaultPlatform:Clone()
Platform.Parent = HallsFolder
Platform.Name = "Hall"..i
Platform.Position = v
Platform.Color = Color3.fromRGB(80,80,80)
table.insert(BridgeParts, Platform)
if i == #HallPlan then
LastBridge = Platform
end
end
local RoomSizeX = GenerateRoom(LastBridge, finalDirection, roomFolder)
if RoomSizeX then
SetBridgeables(roomFolder, RoomSizeX)
for _, v in pairs(roomFolder:GetDescendants()) do
local everythingFine = true
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = PlatformsFolder:GetChildren()
RayParams.FilterType = Enum.RaycastFilterType.Include
local UpRaycastTest = workspace:Raycast(v.Position + Vector3.new(0,100,20), Vector3.new(0,-10000,0), RayParams)
local RightRaycastTest = workspace:Raycast(v.Position + Vector3.new(-20,100,0), Vector3.new(0,-10000,0), RayParams)
local LeftRaycastTest = workspace:Raycast(v.Position + Vector3.new(20,100,0), Vector3.new(0,-10000,0), RayParams)
local DownRaycastTest = workspace:Raycast(v.Position + Vector3.new(0,100,-20), Vector3.new(0,-10000,0), RayParams)
if UpRaycastTest and UpRaycastTest.Instance.Parent ~= roomFolder and UpRaycastTest.Instance.Parent ~= HallsFolder then
everythingFine = false
end
if LeftRaycastTest and LeftRaycastTest.Instance.Parent ~= roomFolder and LeftRaycastTest.Instance.Parent ~= HallsFolder then
everythingFine = false
end
if RightRaycastTest and RightRaycastTest.Instance.Parent ~= roomFolder and RightRaycastTest.Instance.Parent ~= HallsFolder then
everythingFine = false
end
if DownRaycastTest and DownRaycastTest.Instance.Parent ~= roomFolder and DownRaycastTest.Instance.Parent ~= HallsFolder then
everythingFine = false
end
if not everythingFine then
myPart:SetAttribute("Bridgeable"..myDirection, true)
for _, v in pairs(BridgeParts) do
game:GetService("Debris"):AddItem(v, 0)
end
return GenerateRoomProcess(roomFolder, roomType)
end
end
else
myPart:SetAttribute("Bridgeable"..myDirection, true)
for _, v in pairs(BridgeParts) do
game:GetService("Debris"):AddItem(v, 0)
end
return GenerateRoomProcess(roomFolder, roomType)
end
end
end
for x = 1, RoomInfo["MainRoomSizeX"], 1 do
for z = 1, RoomInfo["MainRoomSizeZ"], 1 do
local Platform = DefaultPlatform:Clone()
local PlatformID = x + ((z-1)*RoomInfo["MainRoomSizeX"])
Platform.Parent = MainRoomFolder
Platform.Name = "Platform"..PlatformID
Platform.Color = Color3.fromRGB(0, 255, 0)
Platform.Position = RoomInfo["InitialPosition"] + Vector3.new((x-1)*20,0,(z-1)*20)
end
end
SetBridgeables(MainRoomFolder, RoomInfo["MainRoomSizeX"])
while #RoomsFolder:GetChildren() < RoomInfo["RoomNumber"] do
warn("not enough rooms")
local NewRoom = Instance.new("Folder", RoomsFolder)
NewRoom.Name = "Room"..#RoomsFolder:GetChildren()
if #RoomsFolder:GetChildren() == 1 then
GenerateRoomProcess(NewRoom, "FirstRoom")
else
GenerateRoomProcess(NewRoom, "Room")
end
end
SetBridgeables(HallsFolder, 20)
for _,Platform in pairs(workspace:GetDescendants()) do
local Attributes = {
BridgeableUp = Platform:GetAttribute("BridgeableUp"),
BridgeableDown = Platform:GetAttribute("BridgeableDown"),
BridgeableLeft = Platform:GetAttribute("BridgeableLeft"),
BridgeableRight = Platform:GetAttribute("BridgeableRight"),
}
if Attributes.BridgeableUp then
local Wall = Instance.new("Part", WallsFolder)
Wall.Anchored = true
Wall.Size = Vector3.new(20, 10, 1)
Wall.Position = Platform.Position + Vector3.new(0,5,10)
Wall.Color = Color3.new(0, 0.917647, 1)
Platform.Destroying:Connect(function()
Wall:Destroy()
end)
end
if Attributes.BridgeableDown then
local Wall = Instance.new("Part", WallsFolder)
Wall.Anchored = true
Wall.Size = Vector3.new(20, 10, 1)
Wall.Position = Platform.Position + Vector3.new(0,5,-10)
Wall.Color = Color3.new(0.0431373, 0.435294, 0)
Platform.Destroying:Connect(function()
Wall:Destroy()
end)
end
if Attributes.BridgeableLeft then
local Wall = Instance.new("Part", WallsFolder)
Wall.Anchored = true
Wall.Size = Vector3.new(1, 10, 20)
Wall.Rotation = Vector3.new(0,0,0)
Wall.Position = Platform.Position + Vector3.new(10,5,0)
Wall.Color = Color3.new(1, 0, 0.0156863)
Platform.Destroying:Connect(function()
Wall:Destroy()
end)
end
if Attributes.BridgeableRight then
local Wall = Instance.new("Part", WallsFolder)
Wall.Anchored = true
Wall.Size = Vector3.new(1, 10, 20)
Wall.Rotation = Vector3.new(0,0,0)
Wall.Position = Platform.Position + Vector3.new(-10,5,0)
Wall.Color = Color3.new(0, 0.133333, 1)
Platform.Destroying:Connect(function()
Wall:Destroy()
end)
end
end
Do you know what the issue is that some hallway walls arent being generated?