JointBreaker doesn't completely destroy all welds

Hello. I have this script where a part’s joints can be broken upon contact:

function onTouch(hit)
	if hit:IsA("BasePart") then
		hit:BreakJoints()
		for _, welds in pairs(hit:GetChildren()) do
			if welds:IsA("Weld") or welds:IsA("WeldConstraint") then
				welds:Destroy()
			end
		end
	end
end
script.Parent.Touched:connect(onTouch)

However, it doesn’t completely destroy all welds.


Is there a solution to this?

1 Like

did you checked if the weld destroyed in the explorer ? if you did then are you sure these are Welds or WeldConstraints ? if you do then try replacing GetChildren with GetDescendants

Yes. The photo shows the weldconstraints.

Wouldn’t that give the same result since the welds are children of the parts? (hit)

1 Like

no it will give a different result if the welds are children of other parts then this is the problem , GetChildren returns a table contains all the children of the parent but in this situation you need to use GetDescendants because GetDescendants does not only return the children of the parent it returns the any children of these children it may be hard to understand but just replace GetChildren with GetDescendants

Use :GetJoints() instead of :GetChildren(), it gets all the constraints connected to the part even if the constraints aren’t childs or descendants

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