GetChildren (Method): Difference between revisions
From Legacy Roblox Wiki
Jump to navigationJump to search
>LocalChum grammar |
Fixing page |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<onlyinclude>{{Method | <onlyinclude>{{Method | ||
|name = GetChildren | | name = GetChildren | ||
|returns = | | 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]].< | local children = Workspace:GetChildren() | ||
local children = | |||
for i = 1, #children do | for i = 1, #children do | ||
print(children[i].Name) | print(children[i].Name) | ||
end | end | ||
</ | </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]] | for index, child in pairs(Workspace:GetChildren()) do | ||
for index, | |||
print("Index: ", index) | print("Index: ", index) | ||
print(" | print("Child: ", child) | ||
end | end | ||
</ | </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