API:Class/Instance/DescendantRemoving

DescendantRemoving

Event of Object Icon.pngInstance
RBXScriptSignal DescendantRemoving (
    Instance descendant
)
Parameters:
  1. descendant

Description: Fires before a descendant of the object is removed.

Notes

Do not try to set the descendant's parent to something else when this event fires, or it will fail get the following warning:

workspace.DescendantRemoving:connect(function(descendant)
	descendant.Parent = game
end)
local part = Instance.new("Part")
part.Parent = workspace
part.Parent = nil
--> Something unexpectedly tried to set the parent of Part to NULL while trying to set the parent of Part. Current parent is Workspace.

Example

The following example prints the name of any descendant as it is being removed from the Workspace:

workspace.DescendantRemoving:connect(function(descendant)
	print(descendant.Name .. " is currently parented to " ..  tostring(descendant.Parent))
end)
local part = Instance.new("Part")
part.Parent = workspace
part.Parent = nil
--> Part is currently parented to Workspace
print(part.Parent)
--> nil