Returns an array containing all of the
Running this function will collect every object descending from this
Instance and return them in an array.
Note this function returns all descendants of the
Instance, if only direct children are required use
An array containing the
GetDescendants is often used to do something to all the descendants that are a particular type of object. The code in this example uses GetDescendants and
/Instance/IsA to find all of the parts in the workspace and turns them green.
local descendants = game.Workspace:GetDescendants() -- Loop through all of the descendants of the Workspace. If a -- BasePart is found, the code changes that parts color to green for index, descendant in pairs(descendants) do if descendant:IsA("BasePart") then descendant.BrickColor = BrickColor.Green() end end