API:Class/Instance/ClearAllChildren

ClearAllChildren

Function of Object Icon.pngInstance
void ClearAllChildren ()

Returns: void
Description: Removes all descendants of the object.

Notes

ClearAllChildren uses Destroy to remove the descendants of the Instance.

Example

This example creates a Part and adds a few sparkle objects to the part. Then it calls Part:ClearAllChildren() to remove all of the children.

local part = Instance.new("Part")
 
-- add some sparkles
for i = 1, 3 do
  Instance.new("Sparkles", part)
end
 
print("Part has " .. #part:GetChildren() .. " children")
--> Part has 3 children
 
part:ClearAllChildren()
 
print("Part has " .. #part:GetChildren() .. " children")
--> Part has 0 children