Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I check if a specific part from a model has been destroyed?

Asked by 4 years ago

For context, the model is a vehicle. An explosion can damage it but it will still work. I've included a non-collidable part in the vehicle so when it blows up, the part will fall and get destroyed by the void. I want the vehicle to stop working after it gets damaged, so I tried coming up with a system that detects if the part has been destroyed which will disable the vehicle. I tried doing if (part) == nil then (vehicle stops working), but that doesn't work. I looked through similar questions from the past and read through the wiki, but I still can't find a solution. I don't need help with the disabling of the vehicle, I just need help with finding a way of detecting if a part still exists.

2 answers

Log in to vote
0
Answered by 4 years ago

FindFirstChild

if Model:FindFirstChild("PartYourLookingFor") then
    --Dostuff
end
0
Also combine with or substitute with ChildRemoving User#6546 35 — 4y
0
oh yea that too The_Pr0fessor 595 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

model = script.Parent partToRemove = model:FindFirstChild "PART_NAME_HERE" model.ChildRemoved:Connect (function (p) if p == partToRemove then print (p.Name .. " was removed!") end end)
0
You could also replace ChildRemoved with DescendantRemoving if you need that part before it gets destroyed. MetroidManiac 30 — 4y

Answer this question