local entrancerooms = main_rooms:WaitForChild("Entrances"):GetChildren()
local hallwayrooms = main_rooms:WaitForChild("Hallways"):GetChildren()
local function pickroom()
local folder = nil
local pickedroom = nil
local function pick()
if not folder then
if not main_rooms:WaitForChild("Hallways"):FindFirstChild(roomfrom.Name) then
--print("not prev hallway")
folder = hallwayrooms
else
folder = entrancerooms
end
end
if #folder == 0 then return end
local randroomnum = math.random(1, #folder)
local randroom = folder[randroomnum]
table.remove(folder, table.find(folder, randroomnum))
local genroom = randroom:Clone()
genroom:PivotTo(exitfrom.CFrame * CFrame.Angles(exitfrom.CFrame.Rotation.X, math.rad(180), exitfrom.CFrame.Rotation.Z))
local intersecting = false
local intersected = false
local setvalues = false
for i,v in pairs(genroom:GetDescendants()) do
if v:IsA("BasePart") then
local touchingparts = v:GetTouchingParts()
for index,v in pairs(touchingparts) do
if v.Name ~= "Entrance" then
intersecting = true
break
end
end
local correspondingentrance = exitfrom:WaitForChild("Entrance").Value
if intersecting and not intersected then
intersected = true
--print("found intersection")
genroom:Destroy()
pick()
elseif correspondingentrance and correspondingentrance.Parent == roomfrom then
--warn("bad")
intersected = true
genroom:Destroy()
pick()
end
end
if not intersected and not setvalues then
setvalues = true
--warn("yes")
pickedroom = genroom
end
end
end
pick()
--warn(pickedroom)
return pickedroom
end
local genroom = pickroom()
if not genroom then
return
end
This warning already gives an important clue as to whatâs causing your issue:
If the script is stuck waiting for a child that doesnât exist (or is named differently), then the rest of the code wonât run
The code youâve provided so far donât include a line where Intersection:WaitForChild("DoorAreas") is written, so in-order to be able to fix the problem, Iâll need to see the code that includes it
This could also mean that something is destroying the Intersection, which would also destroy the Instances parented to it, and would explain why WaitForChild is failing to find the DoorAreas
ok sure hereâs my entire function:
(ignore the fact some stuff is repeated, still gotta fix that)
function genmodule:GenerateRoom(exitfrom, roomfrom)
task.wait()
local entrancerooms = main_rooms:WaitForChild("Entrances"):GetChildren()
local hallwayrooms = main_rooms:WaitForChild("Hallways"):GetChildren()
local function pickroom()
local folder = nil
local pickedroom = nil
local function pick()
if not folder then
if not main_rooms:WaitForChild("Hallways"):FindFirstChild(roomfrom.Name) then
--print("not prev hallway")
folder = hallwayrooms
else
folder = entrancerooms
end
end
if #folder == 0 then return end
local randroomnum = math.random(1, #folder)
local randroom = folder[randroomnum]
table.remove(folder, table.find(folder, randroomnum))
local genroom = randroom:Clone()
genroom:PivotTo(exitfrom.CFrame * CFrame.Angles(exitfrom.CFrame.Rotation.X, math.rad(180), exitfrom.CFrame.Rotation.Z))
local intersecting = false
local intersected = false
local setvalues = false
for i,v in pairs(genroom:GetDescendants()) do
if v:IsA("BasePart") then
local touchingparts = v:GetTouchingParts()
for index,v in pairs(touchingparts) do
if v.Name ~= "Entrance" then
intersecting = true
break
end
end
local correspondingentrance = exitfrom:WaitForChild("Entrance").Value
if intersecting and not intersected then
intersected = true
--print("found intersection")
genroom:Destroy()
pick()
elseif correspondingentrance and correspondingentrance.Parent == roomfrom then
--warn("bad")
intersected = true
genroom:Destroy()
pick()
end
end
if not intersected and not setvalues then
setvalues = true
--warn("yes")
pickedroom = genroom
end
end
end
pick()
--warn(pickedroom)
return pickedroom
end
local genroom = pickroom()
if not genroom then
return
end
print(genroom)
for i,v in pairs(genroom:GetChildren()) do
warn(v.Name, genroom)
end
local doorareas = genroom:WaitForChild("DoorAreas")
local possibleEntrances = doorareas:WaitForChild("PossibleEntrances")
local possibleExits = doorareas:WaitForChild("PossibleExits")
local entrancecount = #possibleEntrances:GetChildren()
local pickedentrancenum = math.random(1, entrancecount)
local entrance = possibleEntrances:GetChildren()[pickedentrancenum]
--test
for i,v in pairs(possibleEntrances:GetChildren()) do
v.Transparency = 1
end
genroom.PrimaryPart = entrance
entrance.Parent = genroom
--print(pickedroom.Parent)
local roomnum = Instance.new("IntValue")
roomnum.Name = "RoomNumber"
roomnum.Value = last_gen_room + 1
roomnum.Parent = genroom
genroom:PivotTo(exitfrom.CFrame * CFrame.Angles(exitfrom.CFrame.Rotation.X, math.rad(180), exitfrom.CFrame.Rotation.Z))
local intersecting = false
local intersected = false
local setvalues = false
for i,v in pairs(genroom:GetDescendants()) do
if v:IsA("BasePart") then
local touchingparts = v:GetTouchingParts()
for index,v in pairs(touchingparts) do
if v.Name ~= "Entrance" then
intersecting = true
break
end
end
if intersecting and not intersected then
intersected = true
--print("found intersection")
for i,v in pairs(genroom:GetDescendants()) do
if v:IsA("BasePart") then
v.Color = Color3.new(255,0,0)
end
end
genroom:Destroy()
local exitincompatible = exitfrom:WaitForChild("ExitIncompatible")
exitfrom.Material = Enum.Material.Plastic
exitincompatible.Value = true
exitfrom.BrickColor = BrickColor.new("Medium stone grey")
exitfrom.Transparency = 0
exitfrom.CanCollide = true
end
end
if not intersected and not setvalues then
setvalues = true
genroom.Parent = generated_rooms
last_gen_room = roomnum.Value
for i,v in pairs(genroom:WaitForChild("DoorAreas"):WaitForChild("PossibleExits"):GetChildren()) do
-- test
v.Transparency = 1
local connectedroom = Instance.new("ObjectValue")
connectedroom.Name = "ConnectedRoom"
connectedroom.Value = nil
connectedroom.Parent = v
local exitincompatible = Instance.new("BoolValue")
exitincompatible.Name = "ExitIncompatible"
exitincompatible.Value = false
exitincompatible.Parent = v
end
local connectedroom = Instance.new("ObjectValue")
connectedroom.Name = "ConnectedRoom"
connectedroom.Value = roomfrom
connectedroom.Parent = entrance
local prevroomconnectedroom = exitfrom:WaitForChild("ConnectedRoom")
if genroom then
prevroomconnectedroom.Value = genroom
end
exitfrom.Material = Enum.Material.Plastic
end
end
local correspondingentrance = exitfrom:WaitForChild("Entrance").Value
if correspondingentrance and correspondingentrance.Parent == roomfrom then
warn("bad")
intersected = true
--print("found intersection")
for i,v in pairs(genroom:GetDescendants()) do
if v:IsA("BasePart") then
v.Color = Color3.new(255,0,0)
end
end
genroom:Destroy()
local exitincompatible = exitfrom:WaitForChild("ExitIncompatible")
exitfrom.Material = Enum.Material.Plastic
exitincompatible.Value = true
end
task.wait()
end
If there isnât a reason for genroom to be destroyed if the corresponding entrance exists and its parent is roomfrom, then fixing your issue would be as straight-forward as deleting the line where youâre destroying the genroom, but if itâs your intention to destroy it, then I suspect the issue is that the corresponding entranceâs parent is always being set to roomfrom (or is already roomfrom, instead of starting out as a different Instance or nil), which is causing the if statement to always run
Yeah so basically it needs to because i dont want the exit to come from the entrance (i have seperate parts for each exit and entrance potential spots) so the rooms can be flipped, etc.
local correspondingentrance = exitfrom:WaitForChild("Entrance").Value -- the entrance that the exit your coming from is connected to (not the rooms actual set entrance)
if intersecting and not intersected then
intersected = true
--print("found intersection")
genroom:Destroy()
pick()
elseif correspondingentrance and correspondingentrance.Parent == roomfrom then -- if the entrance matching the exit your trying to come from is the set entrance for the room, it cant exit out of the entrance way, so destroy.
--warn("bad")
intersected = true
genroom:Destroy()
pick()
end
Thing is, it works perfectly fine if i just take out the faulty room and keep the other ones in, thatâs what gets me confused. Do i need to delay the defining of the other room, etc to accommodate for this?
Iâd recommend double checking the faulty room with a room that does work, there could be a small configuration issue thatâs causing all the trouble