I was wondering if there was a way I could maybe reference a for loop in a for loop?

Hello, all of the DevForum.

I was wondering if there was a way I could maybe reference a for loop in a for loop? I’m trying to identify a folder, and when it finds that folder, I use another for loop to get the model inside. I don’t really know how to explain it better. Here is what my code looks like.

for _ , v in pairs(workspace:GetChildren()) do
	if v:IsA('Folder') then
		for __, v2 in pairs(v:GetChildren) do
			print(v2)
		end
	end
end

I most likely look pretty stupid right now.
(Thanks for the help in advance.)

1 Like

Did you forget () for GetChildren here?

Also I would recommend you use more descriptive names since it does look a bit confusing

for _, folder in pairs(workspace:GetChildren()) do
	if folder:IsA('Folder') then
		for _, child in pairs(folder:GetChildren()) do
			print(child)
            --And then just do any more code you want here
		end
	end
end
1 Like

Oh my god. I look so dumb, and yes that was the issue. Thanks for the tip aswell!

1 Like