I made this script to generate rooms when the part is touched but corner rooms can spawn and turn towards the walls of other rooms, so I ask this, how can I make it so that the exit of a room never faces towards another room?
Script:
local Part = script.Parent
local Players = game:GetService("Players")
local Folder = game.ReplicatedStorage.Rooms
local Rooms = Folder:GetChildren()
local function GenerateRoom(Hit)
local Char = Hit.Parent
local Player = Players:GetPlayerFromCharacter(Char)
if Player then
local RoomRNG = math.random(1, #Rooms)
local room = Rooms[RoomRNG]
local Clone = room:Clone()
Clone.Parent = workspace
Clone.PrimaryPart = Clone.StartPart
local cf = Part.CFrame
Clone:SetPrimaryPartCFrame(cf + cf.LookVector)
Part:Destroy()
end
end
Part.Touched:Connect(GenerateRoom)
More information is needed. Are you building a procedural maze, or something like that? Also, what is your specific problem? Are you saying that a room with a bend generates, and its exit doorway is facing the exterior wall of another room? If that isn’t the problem, please explain what the problem is.
It’s supposed to generate the next room in a dungeon when it’s touched, and yes the problem is that a room with a bend can have it’s exit facing towards the exterior of an already existing room.
local Part = script.Parent
local Players = game:GetService("Players")
local Folder = game.ReplicatedStorage.Rooms
local Rooms = Folder:GetChildren()
local function GenerateRoom(Hit)
local Char = Hit.Parent
local Player = Players:GetPlayerFromCharacter(Char)
if Player then
local RoomRNG = math.random(1, #Rooms)
local room = Rooms[RoomRNG]
local Clone = room:Clone()
Clone.Parent = workspace
Clone.PrimaryPart = Clone.StartPart
local cf = Part.CFrame
Clone:SetPrimaryPartCFrame(cf + cf.LookVector)
for _, v in ipairs(Clone:GetDescendants()) do
if v.Name == "GeneratePart" then
local Touching = v:GetTouchingParts()
if Touching[1] then
Clone:Destroy()
GenerateRoom(Hit)
end
end
end
Part:Destroy()
end
end
Part.Touched:Connect(GenerateRoom)