Model doesn't load any children when they are in folders

Here it is:

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
1 Like

weird, this seems fine too. either that or im too blind to spot the error

1 Like

just realized smth, you’re using table.remove on a folder? folder isnt a table tho

1 Like

it’s the folder in table form like :GetChildren()

1 Like

ah ic, the only thing i can think of atm is remove the comments from the warns and start debugging on whats going on in the script

1 Like

Genuinely think it’s a studio bug:

image
Works!

image
Nope, doesn’t work.

Ctrl + Z
image
Doesn’t work still, even though it’s the same as the first which did work…

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


@Jhettblocks789

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

Try commenting out each genroom:Destroy(), and see if the issue persists

If the problem is solved, then that would indicate that the if statements where genroom is destroyed are being triggered incorrectly

1 Like

oh damn dude, yeah that’s the problem, I singled it out to this if statement:

1 Like

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

welp, i figured it out

Before:

After:
image

I nested it with all the other elseif’s and now it works fine, now really sure how that fixes it but thanks for helping me out!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.