PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

ChildAdded

Fires when an object is parented to this Instance.

Note, when using this function on a client to detect objects created by the server it is necessary to use Instance/WaitForChild when indexing these object’s descendants. This is because the object and its descendants are not guaranteed to replicate from the server to the client simultaneously. For example:

workspace.ChildAdded:Connect(function(child)
	-- need to use WaitForChild as descendants may not have replicated yet
	local head = child:WaitForChild("Head")
end)

Note, this function only works for immediate children of the Instance. For a function that captures all descendants, use Instance/DescendantAdded.

See also, Instance/ChildRemoved.

Parameters

Name Type Default Description

The Instance that has been added.


Code Samples


Instance.ChildAdded

This snippet prints the names of objects as they are added to the Workspace:

workspace.ChildAdded:Connect(function(instance)
    print(instance.Name .. " added to the workspace")
end)
Instance.new("Part", workspace)
--> Part added to the Workspace