When any part is touched by a fast part it gets destroyed but when i use the car it's constantly touching it's own parts

I made a breaking system so when any part is touched it would break if the part is fast or heavy enough, but when i test it out with a car all the parts collide with each other and they all break.

I tested detecting if the part that’s getting touched is a child of the same car, but i couldn’t figure it out.

Script 2 is inside script 1 and script 1 is inside ServerScriptService

Script1:

local Script = script.Script

for i, part in pairs(workspace:GetDescendants()) do
	if part:IsA("BasePart") or part:IsA("MeshPart") or part:IsA("UnionOperation") and part.Parent:FindFirstChild("Humanoid", false) then
		Script:Clone().Parent = part
	end
end

Script2:

FragmentSmasher = require(game.ServerStorage.FragmentSmasher)
local materials = {
	[Enum.Material.Metal] = {
		["Multiplier"] = 1.5
	},
	[Enum.Material.Plastic] = {
		["Multiplier"] = 0.75
	},
	[Enum.Material.Fabric] = {
		["Multiplier"] = 0.5
	},
	[Enum.Material.Rock] = {
		["Multiplier"] = 1.5
	},
	[Enum.Material.Pavement] = {
		["Multiplier"] = 1.5
	},
	[Enum.Material.Sand] = {
		["Multiplier"] = 0.5
	},
	[Enum.Material.Snow] = {
		["Multiplier"] = 0.5
	},
	[Enum.Material.Mud] = {
		["Multiplier"] = 0.75
	},
	[Enum.Material.Ground] = {
		["Multiplier"] = 1
	},
	[Enum.Material.Grass] = {
		["Multiplier"] = 0.75
	},
	[Enum.Material.LeafyGrass] = {
		["Multiplier"] = 0.75
	},
	[Enum.Material.Pebble] = {
		["Multiplier"] = 1
	},
	[Enum.Material.Wood] = {
		["Multiplier"] = 1
	},
	[Enum.Material.WoodPlanks] = {
		["Multiplier"] = 0.75
	},
	[Enum.Material.Concrete] = {
		["Multiplier"] = 1.5
	},
	[Enum.Material.Glass] = {
		["Multiplier"] = 1.25
	},
	[Enum.Material.Marble] = {
		["Multiplier"] = 1
	},
	[Enum.Material.Ice] = {
		["Multiplier"] = 1
	},
	[Enum.Material.Cobblestone] = {
		["Multiplier"] = 1.5
	},
	[Enum.Material.Brick] = {
		["Multiplier"] = 1.5
	},
	[Enum.Material.DiamondPlate] = {
		["Multiplier"] = 1.5
	},
	[Enum.Material.SmoothPlastic] = {
		["Multiplier"] = 0.75
	},
}
repeat task.wait() until script.Parent:IsA("MeshPart") or script.Parent:IsA("BasePart") or script.Parent:IsA("UnionOperation")

local part = script.Parent

part.Touched:Connect(function(hit)
	local model = hit:FindFirstAncestorWhichIsA("Model")	
	if model.Name == "Misc" or model.Name == "Body" or model.Name == "Wheels" then
		car = model.Parent
	else
		model = model:FindFirstAncestorWhichIsA("Model")
		return
	end
	print(hit.Material)
	if hit.Velocity.magnitude > (30 / materials[hit.Material].Multiplier) and hit.Mass > (32 * part.Mass) and not hit:IsDescendantOf(car) then
		
		FragmentSmasher.BreakSurface(
			hit,
			hit.Position,
			Vector3.new(0, 0 ,0),
			2174790942,
			10
		)
		wait(10)
		car:Destroy()
	end
end)

part.Touched:Connect(function(hit)
	local times = 0
	local model = hit:FindFirstAncestorWhichIsA("Model")
	print(hit.Material)
	if hit.Velocity.magnitude > (30 / materials[hit.Material].Multiplier) and times > 3 and not hit:IsDescendantOf(car) then
		FragmentSmasher.BreakSurface(
			part,
			part.Position,
			Vector3.new(0, 0 ,0),
			2174790942,
			10
		)
		wait(10)
		car:Destroy()
	end	
	if model.Name == "Misc" or model.Name == "Body" or model.Name == "Wheels" then
		car = model.Parent
	elseif times < 4 then
		model = model:FindFirstAncestorWhichIsA("Model")
		times += 1
		return
	end
	
end)


Just have all the car Parts in a CollisionGroup that is set so that the group doesn’t collide with itself.

I use this same setup for making tank tracks. None of the treads in the group collide with each other, but will collide with the Default group. It also helps with the lag caused by the calculation of all those hits not having to be calculated in the physics engine.

1 Like

omg thank you so much. i know the method but i didn’t think about it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.