Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to Call Functions When Something is Destroyed?

How would I go about a function running only when a certain brick/object 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.

4 comments

0

That second one won't work.

0

Edited so it works now

0

Is there a way to do this from the part to be destroyed? Like a script inside of it?

0

.... if you place a script inside the part, the script gets deleted as well.

This discussion is preserved as it was. New answers, comments, and votes are closed.