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

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

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

✓ Accepted answer

FindFirstChild

if Model:FindFirstChild("PartYourLookingFor") then
	--Dostuff
end

2 comments

0

Also combine with or substitute with ChildRemoving

0

oh yea that too


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)


1 comment

0

You could also replace ChildRemoved with DescendantRemoving if you need that part before it gets destroyed.

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