Parts not loading?

for _, v in pairs(Gifts:GetChildren()) do
	for _, box in pairs(v:GetChildren()) do
		print(box.Name)
    end
end


Output only prints Ribbon, and never the parts. The problem with this is after I try to do .Touched, like so

for _, v in pairs(Gifts:GetChildren()) do
	for _, box in pairs(v:GetChildren()) do
        print(box.Name)
		if box:IsA('Part') then
            print('Is a part') -- this never prints
            box.Touched:Connect(function()

            end)
        end
    end
end
1 Like

I think it has to do with the _ counters. It may be messing up the value between the two loops (I know it does with other variables, _ might be special but not 100%)

Try changing one of them and see if that fixes it

for i, v in pairs(Gifts:GetChildren()) do
	for ii, box in pairs(v:GetChildren()) do
		print(box.Name)
    end
end

Still only prints Ribbon

print(#v:GetChildren()) returns 1 aswell, instead of 3, but as you can see


There is clearly 3 items in each model

This is really strange; it should work.
Perhaps post the whole script and we can see what you’ve done?

for ii, box in pairs(v:GetChildren()) do

Also I’m assuming thats just a typo?

EDIT: I read it wrong, my bad.

What’s the value for Gifts? At this point I’m assuming it’s just looking at the wrong thing. It should be finding the parts

It was

local Gifts = workspace:WaitForChild(‘Gifts’)

I’ve since changed it, so the for loop goes through it

for _, v in pairs(worksapce.Gifts:GetChildren()) do

end
2 Likes

Not sure why you’re not using :GetDescendants()?

2 Likes

What’s the difference between using GetChildren and GetDescendants()

You can actually use both. Call everything that’s directly in the parent model with :GetDescendants(), then based off that you can implement the :GetChildren that’ll read whatevers in any child models. The api shows a almost spot on example of what you’re trying to achieve: Instance | Documentation - Roblox Creator Hub