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

How does :GetChildren() Work?

Asked by 9 years ago

How does :GetChildren() Work? For example if I wanted to get all the Children of Workspace and then change a property of an object if it has a certain name.

1 answer

Log in to vote
0
Answered by
SanityMan 239 Moderation Voter
9 years ago

The :GetChildren() Method is a method that many scriptures use. It can be used on virtually an object.

Using something like game.Players:GetChildren() will return a table of all of the hierarchical Children of game.Players. This is very useful in iterating loops, such as for loops, because you can run through a table and effect each child. In your case, you would want to do something like this:

local name = "Part"

for key, value --[[how it will run the loop]] in pairs(game.Workspace:GetChildren() --[[Our table]]) do
    if value.Name == name then --if the certain child's Name is the desired name then
        value.Name = "ChangedPart" --change the certain child's Name to "ChangedPart"
    end --end the if scope
end --end the loop scope

Check out this article on :GetChildren()

Hope this helped your understanding!

0
Thanks! BosswalrusTheCoder 88 — 9y
0
No problem! SanityMan 239 — 9y
Ad

Answer this question