Hello there, I’m making a car crash physics and for some reason when a part breaks it breaks every other part in the car.
Here is the script:
local Matar = script.Parent:WaitForChild('Motor')
local Crash = false
local NumberOfHit = 0
local RS = game:GetService('ReplicatedStorage')
local RUN_EVENT = RS:FindFirstChild('RUN_EVENT')
local BODY = script.Parent
local CRASHSOUND = script:FindFirstChild('Crash')
Matar.Touched:Connect(function(hit)
--print(hit)
--print(hit.Name)
if hit.Parent == hit:FindFirstAncestor("Body") or hit.Parent == hit:FindFirstAncestor("Wheels") or hit.Name == "Baseplate" then
--print('NO EXPLOSION *SAD CAT NOISE :CCCCCCCCCCC*')
elseif Matar.Velocity.Magnitude >= 100 then
print('HAHAHHA BIG EXPLOSION *HAPPY CAT NOISE*')
--[[local exp = Instance.new('Explosion')
exp.BlastRadius = 1
exp.BlastPressure = 1
exp.Parent = Matar
exp.Position = Matar.Position]]
end
end)
RUN_EVENT.OnServerEvent:Connect(function()
for i,v in pairs(BODY:GetChildren()) do
if v:IsA('UnionOperation') or v:IsA('Part') or v:IsA('MeshPart') then
if not v:FindFirstAncestor('Body') or not v:FindFirstAncestor('Wheels') then
if not v:FindFirstChild('TouchInterest') then
v.Touched:Connect(function(hit)
if hit.Velocity.Magnitude >= 30 or v.Velocity.Magnitude >= 30 then
if not hit:FindFirstAncestor('Body') or not hit:FindFirstAncestor('Wheels') then
if hit.Name ~= 'Axle' then
if not v:FindFirstChild('Crashed') then
local crashsound = CRASHSOUND:Clone()
crashsound.Parent = v
--crashsound.SoundId = '8125594257'
crashsound:Play()
print('played')
--wait(crashsound.TimeLength)
--crashsound:Destroy()
print("Destroyed")
local Crashed = Instance.new('BoolValue')
Crashed.Name = 'Crashed'
Crashed.Parent = v
Crashed.Value = true
if v:FindFirstChild('TouchInterest') then
--v:FindFirstChild('TouchInterest'):Destroy()
v:BreakJoints()
v.Anchored = false
v.Parent = workspace
--v.CFrame = v.CFrame * CFrame.new(0.1,0,0)
else
v:BreakJoints()
v.Anchored = false
v.Parent = workspace
--v.CFrame = v.CFrame * CFrame.new(0.1,0,0)
end
end
end
end
end
end)
else
--v:FindFirstChild('TouchInterest'):Destroy()
end
end
end
end
end)
thank you for reading this!