:GetDescendants isn't working in loops?

Hey there! As the title states, I’m currently having issues with the :GetDescendants method. When I print the partDirectory’s descendants, I am given a table consisting of all instances that are under partDirectory. However, when I make an attempt to loop through them, I am greeted with only two instances. What could be causing this issue; what am I doing wrong?

Thanks in advance. :grin:

image

My script:

function Radon:HandleTransparency(partTransparency : number, partDirectory : Instance)
	if #self.TransparentParts>0 then
		for i, v in pairs(self.TransparentParts) do
			v.Transparency = partTransparency --//Set the transparency of the instance to the partTransparency variable, which is a defined number
		end

		return
	end
	
	table.insert(self.TransparentParts,self.Character["Right Arm"])
	table.insert(self.TransparentParts,self.Character["Left Arm"])
	
	for i, v in pairs(partDirectory:GetDescendants()) do --//Loop through all instances present inside of the given directory
		local v = partDirectory:GetDescendants()[i]
		print(v.Name)
		if (not v:IsA("BasePart") and not v:IsA("MeshPart")) or (partTransparency==1 and v.Transparency==1) then 
			return --//Return if the instance is not a basepart, a meshpart, or if the instance is meant to be transparent
		end

		v.Transparency= partTransparency --//Set the transparency of the instance to the partTransparency variable, which is a defined number
		table.insert(self.TransparentParts, v); --//Insert the instance into the 'AfflictedParts' table
	end
end

I tested out what you have and it works fine for me, Is this running before everything fully loads in? and just as a side question, is there a reason you are defining v for a second time inside the for loop.

I misread and didn’t realize it is giving you the entire table, but you can’t loop through it. The reason it only gives a few and then stops is that you are having it return the moment anything isn’t a basepart. so as soon as it finds anything that isn’t a basepart then it just ends the entire loop

Shoot! You’re right; I forgot to wrap the function. Thanks, mate.

The reason that I defined v a second time was because I was testing different loops out. :skull: