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

for loops not working/Getchildren func(simple)?

for i =1,#vs2:GetChildren() do
	vs2[i].Parent = player
end

so basically vs2 is an object value that has loads of variables in the hierarchy, and I want all the children to have the parent of the player, when I run this code it says 1 is not a valid member of object value? I think I've just confused myself here, thanks for the help

1 answer

✓ Accepted answer

vs2 is the object, not the table. vs2:GetChildren()[i] is what you want. However, I suggest using a generic for loop instead. It's cleaner in my opinion. I've provided both solutions below.

-- Solution One
for i =1,#vs2:GetChildren() do
    vs2:GetChildren()[i].Parent = player
end

-- Solution Two

for i,v in pairs(vs2:GetChildren()) do
	v.Parent = player
end 

Good Luck!

If I helped, please don't forget to accept my answer.

1 comment

0

ahhh okay such a silly mistake, thanks man

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