Grouping welded parts script being very sensative

I have a script that groups welded parts into a model and separates each welded section into a separate model, each part has a copy of each weld its effected by to make referencing parts easier. But the script keeps cutting off parts that are welded:

local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {Modal}
local EE = {}
function A(Part,Parth)
	if Part:IsA("BasePart") then
		for i,v in workspace:GetPartBoundsInBox(Part.CFrame,Part.Size*1.1,params) do
			if not table.find(Parth,v) then
				for i,v in v:GetChildren() do
					if v:IsA("WeldConstraint") and ((v.Part0 == v.Parent and v.Part1 == Part) or (v.Part1 == v.Parent and v.Part0 == Part)) then
						table.insert(EE,v.Parent)
						table.insert(Parth,v.Parent)
						if v.Part0 == v.Parent then
							A(v.Part1,Parth)
						else
							A(v.Part0,Parth)
						end
					end
				end
			end
		end
	end
end

for i,v in Modal:GetChildren() do
	A(v,{})
	if #EE ~= 0 then
		local Mo = Instance.new("Model")
		Mo.Parent = workspace
		for i,v in EE do
			v.Parent = Mo
		end
	end
	EE = {}
end

How do I make it less trigger happy?

1 Like