Fires when the
Instance/Parent property of the object or one of its ancestors is changed.
This event includes two parameters, child and parent. Child refers to the
Instance/Parent was actually changed. Parent refers to this
A common use for this function is detecting when an object has been removed or destroyed (using
Instance/Destroy). This is done by checking if the parent has been set to nil. For example:
object.AncestryChanged:Connect(function(_, parent) if not parent then print("object destroyed!") end end)
The below example would print “Part is now a child of Model”.
local p = Instance.new("Part") p.Parent = game.Workspace p.AncestryChanged:Connect(function(child, parent) print(child.Name.." is now a child of "..parent.Name) end) p.Parent = Workspace.Model