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

How to select children?

Is there a way you can select a child with doing .ChildName. This would be useful if you do not know the child name but you know there is only one child.

2 comments

0

What do you mean by "ChildName"? Do you mean the ClassName?

0

You mean :GetChildren() ?

3 answers

✓ Accepted answer

You can get all of the children of a model using :GetChildren(). This returns a list.

If you're sure there's only one, you can just get the first thing in that list.

local model = ..... something something .....

local children = model:GetChildren()
assert(#children == 1) -- assert that there is only one child

local theOneChild = children[1]

1 comment

0

Yay, I learned a new function.

Ultimately you could use the :GetChildren() command and then use the for i,v in pairs do() command.

For this, you would want to specify the parent's location. For example:

local part = game.Workspace.Part:GetChildren


for i,v in pairs(part) do
v.Name = "hi"
end

This code will rename the part that that is under the parent (game.Workspace.Part). The :GetChildren() command looks under the parent that you specify, in this case, the Part in the workspace. The command will then give a table showing all the parts, and you can use the for i,v in pairs() do command to 'decode' the table to edit the properties of the children. Since you are only wanting to use 1 child, the script will automatically stop after all the children have been edited.

Hope this answers your question!

1 comment

0

You forgot the ()'s after GetChild on line 1 of your code. XD

It will not work because there is no "child" property.

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