Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to select children?

Asked by 7 years ago

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.

0
What do you mean by "ChildName"? Do you mean the ClassName? antonio6643 426 — 7y
0
You mean :GetChildren() ? RubenKan 3615 — 7y

3 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago

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]
0
Yay, I learned a new function. OldPalHappy 1477 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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!

0
You forgot the ()'s after GetChild on line 1 of your code. XD TheeDeathCaster 2368 — 7y
Log in to vote
-1
Answered by
wookey12 174
7 years ago

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

Answer this question