So I have a car in my game, which has crash physics, basically theres a script in some key parts that will :BreakJoints() (simulating a car crash), but, I ran into an issue, the car itself would touch it’s own parts and destroy itself, so I tried to implement a system for it to check two things:
- The thing it is hitting is NOT a player (humanoid)
- The thing it is hitting is NOT a descendant of itself.
Here is my code:
function onTouched(hit)
local car = script.Parent.Parent.Parent
if not hit.Parent:FindFirstChild([[Humanoid]]) and not hit:IsADescendantOf(car) then
hit:BreakJoints()
end
end
connection = script.Parent.Touched:connect(onTouched)
So it fixes it, but it also makes it so it can’t destroy any other cars it touches outside of itself, and any time it touches a part, it gives the error: " IsADescendantOf is not a valid member of Part part it touched"
Can someone please help, thanks!