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.
✓ ANSWER ACCEPTED
How does :GetChildren() Work?
1 answer
✓ Accepted answer
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!
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Thanks!
No problem!