GetChildren (Function): Difference between revisions

From Goodblox Wiki
Jump to navigationJump to search
(Created page with "<onlyinclude>{{Function| name = GetChildren |arguments = |returns = Table ''children'' |description = Returns a read-onl...")
 
mNo edit summary
Line 1: Line 1:
{{CatUp|Functions}}
<onlyinclude>{{Function|
<onlyinclude>{{Function|
name                  = GetChildren
name                  = GetChildren
Line 9: Line 10:
==Example==
==Example==
(Simple example)
(Simple example)
<pre>
<pre>
 
local children = workspace:GetChildren()
local children = game.Workspace:GetChildren()
for c = 1, #children do
for c = 1, #children do
    print(children[c].Name)
    print(children[c].Name)
end
end
</pre>
</pre>


(More efficient example)
(More efficient example)
<pre>
<pre>
local children = game.Workspace:GetChildren()
local children = workspace:GetChildren()
for i, j in ipairs(children) do
for i, item in pairs(children) do
    print("index: ")  --j is the object, i is the index of the table it is at
    --"item" is the object, "i" is the index of the table it is at
    print(i)
    print("index: "..i)
    print("Object: ")
    print("Object: "..item)
    print(j)
end
end
</pre>
</pre>


[[Category:Functions]]
[[Category:Functions]]

Revision as of 20:47, 23 September 2021

Function
Syntax GetChildren( )
Returns Table children
Description: Returns a read-only table of this Object's children
In Object: Global


Example

(Simple example)

local children = workspace:GetChildren()
for c = 1, #children do
     print(children[c].Name)
end

(More efficient example)

local children = workspace:GetChildren()
for i, item in pairs(children) do
     --"item" is the object, "i" is the index of the table it is at
     print("index: "..i)
     print("Object: "..item)
end