GetChildren (Method): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>LocalChum
grammar
Fixing page
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
<onlyinclude>{{Method
<onlyinclude>{{Method
|name                = GetChildren
  | name                = GetChildren
|returns              = [[Table]] ''children''
  | returns              = {{type|table}}
|description          = Returns a read-only table of the object's children.
  | description          = Returns a read-only {{type|table}} of the object's children.
|object              = Instance
  | object              = Instance
}}</onlyinclude>
}}</onlyinclude>
{{clear floats}}
{{clear floats}}
 
{{Example|Using GetChildren with a [[Loops#The_for_loop|for loop]].<syntaxhighlight lang="lua">
{{Example|Using GetChildren with a [[Loops#The_for_loop|for loop]].<pre>
local children = Workspace:GetChildren()
local children = game.Workspace:GetChildren()
for i = 1, #children do
for i = 1, #children do
     print(children[i].Name)
     print(children[i].Name)
end
end
</pre>}}
</syntaxhighlight>}}
 
{{Example|It is highly recommended to use GetChildren with a [[Generic for|generic for loop]].<syntaxhighlight lang="lua">
{{Example|It is highly recommended to use GetChildren with a [[Generic for]] loop.<pre>
for index, child in pairs(Workspace:GetChildren()) do
for index, object in ipairs(game.Workspace:GetChildren()) do
     print("Index: ", index)
     print("Index: ", index)
     print("Object:", object)
     print("Child: ", child)
end
end
</pre>}}
</syntaxhighlight>}}
 
[[Category:Methods]]
[[Category:Methods]]

Latest revision as of 00:10, 18 April 2023

GetChildren( )
Returns table
Description: Returns a read-only table of the object's children.
Member of: Instance
Example
Using GetChildren with a for loop.
local children = Workspace:GetChildren()
for i = 1, #children do
    print(children[i].Name)
end
Example
It is highly recommended to use GetChildren with a generic for loop.
for index, child in pairs(Workspace:GetChildren()) do
    print("Index: ", index)
    print("Child: ", child)
end