Hi, im making a simulator game but i dont know how to detect a cloned part when its destroyed please help if you know, thanks!
Well, there’s no event spesifically for detecting an instance being destroyed. However, you can use the AncestryChanged
event to detect when it’s parent is set to nil.
local part = game.Workspace.Part:Clone()
part.Parent = game.Workspace
game.Workspace.ChildRemoved:Connect(function(child)
if child == part then
print("Cloned Part Removed")
end
end)
I did not test the code, so tell me if it doesn’t work so I can fix it.
id use :FindFirstChild(partname) its prob the most simpliest methods
Why not just add another line of code after you destroyed the part?
local part = Instance.new("BasePart")
local clonedPart = part:Clone()
clonedPart:Destroy()
-- other stuff after Destroy is called
local cloned = aThing:Clone()
cloned.AncestryChanged:Connect(function()
local exist = cloned and cloned.Parent
if not exist then
print("twinkle twinkle little star")
-- removed
end
end)