Instance.Destroying not working

I’m not sure what is wrong with my code but it doesn’t seem like Instance.Destroying is working

local Folder = Instance.new("Folder")
Folder.Parent = workspace
local Part = Instance.new("Part")
Part.Parent = Folder

Part.Destroying:Connect(function()
	print(Part, "Destroyed")
end)

task.wait(1)

Folder:Destroy()
Part:Destroy()

am I doing something wrong?

1 Like

Roblox hasn’t fully released that event yet. Use GetPropertyChangedSignal instead to detect when the parent property changes to nil.

local Part = workspace:WaitForChild("Part")
Part:GetPropertyChangedSignal("Parent"):Connect(function()
	if not Part.Parent then
		print("destroyed")
	end
end)


11 Likes
local Folder = Instance.new("Folder")
Folder.Parent = workspace
local Part = Instance.new("Part")
Part.Parent = Folder

Folder.ChildRemoved:Connect(function(child)
    if (child == Part) then
        print(Part, "Destroying");
    end
end)

task.wait(1)

Folder:Destroy()
Part:Destroy()

try smth like this ig

1 Like

Destroying Event doesn’t work at all so you gotta use something else

3 Likes

how about ChildRemoved it might work

oh im not reading mb this is .

Your best bet is just to use AncestryChanged and detect if the part has a parent at all.

local part = workspace.Part
part.AncestryChanged:Connect(function()
  if not part.Parent then
    print("Cya part")
  end
end)

I think roblox have successfully implemented Instance.Destroying event

1 Like

I tried using it with characters and it still isn’t firing.

The current best alternative is .AncestryChanged

Part.AncestryChanged:Connect(print) --The instance that got changed, New parent

Unrelated funfact: You can connect print directly to any event and it’ll print everything they pass.

5 Likes

This is also a good work-around for a bug where a custom character does not trigger a died, destroyed, or removing event when it falls into the void! Thanks!

local diedToVoidEvent: RBXScriptConnection
		diedToVoidEvent = char:GetPropertyChangedSignal("PrimaryPart"):Connect(function()
			if not char.PrimaryPart then
               print(player,'died to void.')
				diedToVoidEvent:Disconnect() --make a new connection inside CharacterAdded event
				wait(game.Players.RespawnTime)
				player:LoadCharacter()
			end
		end)
1 Like