GetChildren (Method): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>LocalChum
grammar
>JulienDethurens
Did some small changes.
Line 8: Line 8:
{{clear floats}}
{{clear floats}}


{{Example|Using GetChildren with a [[Loops#The_for_loop|for loop]].<pre>
{{Example|Using GetChildren with a [[Loops#The_for_loop|for loop]].<code lua>
local children = game.Workspace:GetChildren()
local children = Workspace:GetChildren()
for i = 1, #children do
for i = 1, #children do
     print(children[i].Name)
     print(children[i].Name)
end
end
</pre>}}
</code>}}


{{Example|It is highly recommended to use GetChildren with a [[Generic for]] loop.<pre>
{{Example|It is highly recommended to use GetChildren with a [[Generic for|generic for loop]].<code lua>
for index, object in ipairs(game.Workspace:GetChildren()) do
for index, child in pairs(Workspace:GetChildren()) do
     print("Index: ", index)
     print("Index: ", index)
     print("Object:", object)
     print("Child: ", child)
end
end
</pre>}}
</code>}}


[[Category:Methods]]
[[Category:Methods]]

Revision as of 02:57, 18 January 2012

GetChildren( )
Returns Table children
Description: Returns a read-only table of the object's children.
Member of: Instance


Example
{{{1}}}


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