PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

GetChildren

Returns an array (a numerically indexed table) containing all of the Instance's direct children, or every Instance whose Instance/Parent|Parent is equal to the object. The array can be iterated upon using either a numeric or generic for-loop:

-- Numeric for-loop example
local children = workspace:GetChildren()
for i = 1, #children do
	local child = children[i]
	print(child.Name .. " is child number " .. i)
end
-- Generic for-loop example
local children = workspace:GetChildren()
for i, child in ipairs(children) do
	print(child.Name .. " is child number " .. i)
end

The children are sorted by the order in which their Instance/Parent|Parent property was set to the object.

See also the Instance/GetDescendants|GetDescendants function.

Returns

Return Type Summary

An array containing the Instance's children.


Code Samples


Instance:GetChildren

The below would print the name of all objects currently in Workspace when ran.