How to make attachments break apart by explosions

More like this:

e.Hit:Connect(function(part)	--In this code, "distance" can be excluded because it's relative to the hit part.
	local blast_distance = e.BlastRadius * e.DestroyJointRadiusPercent	--This will give us the destructive range of the explosion
	
	for _,child in ipairs(part:GetChildren()) do	--This will iterate through all children of the part.
		if child:IsA("Attachment") then	--You got this part right.
			--Now, we need to compare the position of Attachment to the explosion, since the part
			--is in range of the explosion, but Attachment children may not be.
			if (child.WorldPosition - e.Position).Magnitude <= blast_distance then
				child:Destroy()
			end
		end
	end
end)

This code will need to go in whatever script is creating the explosion, and I’m working under the assumption that “e” is the variable for the created explosion.

1 Like