How would I go about a function running only when a certain brick/object is destroyed?
COMMUNITY QUESTION
How to Call Functions When Something is Destroyed?
1 answer
There are many ways to be honest. I'll list a couple.
1st one would be using the .ChildRemoved event on its parent and checking for the part.
local parent = workspace
local part = parent:FindFirstChild("Part")
parent.ChildRemoved:Connect(function(removedPart)
if removedPart == part then
--script
end
end)
The second one can be simply waiting for the part to disappear, then continuing the script.
repeat wait() until not workspace:FindFirstChild("Part")
-- script
I'm sure you can find others, these were just some examples, hope this helped.
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
That second one won't work.
Edited so it works now
Is there a way to do this from the part to be destroyed? Like a script inside of it?
.... if you place a script inside the part, the script gets deleted as well.