Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my for loop not running, but everything else is?

I'm working on a project where when a player goes through a door, the area beyond the door appears, to create a "bigger on the inside than it looks on the outside" effect. I made a folder that contains the parts to appear and made a loop that iterates through all of the children of it, I set their transparency to 0, and CanCollide to true. However, when I tested this the area beyond the door did not appear. After lots of debugging, I found that when this is run:

function LoadFolder(load, folder)
	print("1")
	local children = folder:GetChildren()
	
	if load == true then
		print("2")
		for i,child in pairs(children) do
			print("3")
			--child.Transparency = 0
			--child.CanCollide = true
		end
	
	elseif load == false then
		print("2")
		for i,child in pairs(children) do
			print("3")
			--child.Transparency = 1
			--child.CanCollide = false
		end
	end
	print("4")
end

The output is: 1 2 4

It seems to ignore the loop completely!

Can someone please help me figure out what's going wrong?

9 comments

0

It means that there's nothing in the variable folder.

0

There are three parts in the folder.

0

It's the only explanation, the children of "folder" are 0. Check carefully the variable folder when the function is called and provide some screenshot if you still can't figure out the problem

0

Look: imgur.com/a/PIB0H2P

0

print #folder and see what it prints.

0

and that image was taken while the game was running?

0

It gives the error "attempt to get length of a Instance value"

0

That image was not taken while the game was running. I just noticed that for some reason ~3 seconds into running the game all of the children of the folder disappear. I don't know what's causing it. I think that's the reason for why the loop isn't working. Why is this happening?

0

What other scripts affect the folder?

1 answer

I figured it out. The parts had CanCollide off but they weren't anchored, so they despawned when they fell too far. It's working now.

This discussion is preserved as it was. New answers, comments, and votes are closed.