Autoweld scripts not working

I am trying to make the parts automatically weld to eachother after splitting but then this happens

This is not what needs to happen, pls help me
This is the module i am using:


local module = {}
module.VoxelSize = 2

function module:_clonePart(template): BasePart
	local part = template:Clone()
	part.Parent = template.Parent

	return part
end

function module:_getPartsInBounds(cframe: CFrame, size: Vector3 | number, params: OverlapParams?): {BasePart}
	if tonumber(size)  then
		return workspace:GetPartBoundsInRadius(cframe.Position, size, params)
	else
		return workspace:GetPartBoundsInBox(cframe, size, params)
	end
end

local function weldparts(x : Part, y, C0,C1)
	local W = Instance.new("Weld")
	W.Parent = x
	W.C0 = C0
	W.C1 = C1
	wait(0)
	W.Part0 = x
	W.Part1 = y
	

end

local function weld(part)
	spawn(function()
		
		part:ClearAllChildren()
		local piece = part
		local params = OverlapParams.new()
		params.RespectCanCollide = true
		params.CollisionGroup = "plrs"
		piece.Size = piece.Size * 1.1
		local parts = workspace:GetPartsInPart(piece)
		piece.Size = piece.Size / 1.1
		
		for c,i in pairs(parts) do
			weldparts(piece,i,piece.CFrame:Inverse(),i.CFrame:Inverse())
		end
		
		piece.Anchored = false
	end)
	
	
end

function module:DividePart(part: BasePart, axis: Vector3)
	local a = module:_clonePart(part)
	local b = module:_clonePart(part)

	a.Size = part.Size * (-(axis/2)+Vector3.new(1,1,1))
	a.CFrame = part.CFrame * CFrame.new(-part.Size * (Vector3.new(1,1,1)*axis/4))	

	b.Size = part.Size * (-(axis/2)+Vector3.new(1,1,1))
	b.CFrame = part.CFrame * CFrame.new(part.Size * (Vector3.new(1,1,1)*axis/4))
	weld(a)
	weld(b)
	
end

function module:SubdivdePart(part: BasePart, size: number?): boolean
	size = size or module.VoxelSize
	if part.Size.X / 2 < size and part.Size.Y / 2 < size and part.Size.Z / 2 < size then return false end

	local axis = math.max(part.Size.X, part.Size.Y, part.Size.Z)
	if axis == part.Size.X then
		module:DividePart(part, Vector3.new(1,0,0))
	elseif axis == part.Size.Y then
		module:DividePart(part, Vector3.new(0,1,0))
	else
		module:DividePart(part, Vector3.new(0,0,1))
	end

	part:Destroy()
	return true
end

function module:PartDividable(part: BasePart)
	if not part:IsA("Part") then return false end
	if part.Shape ~= Enum.PartType.Block then return false end
	if part.Parent:FindFirstChildOfClass("Humanoid") then return false end
	if part.Parent:IsA("Accessory") then return false end
	if part:HasTag("NonDestructible") then return false end
	if part.Name == "Baseplate" then return false end

	return true
end

function module:DestroyPartsInBounds(cframe: CFrame, size: Vector3 | number, params: OverlapParams?, voxelSize: number?, callback: (BasePart) -> ()?)
	local parts
	local toweld = {}
	repeat
		parts = module:_getPartsInBounds(cframe, size, params)
		if #parts == 0 then break end
		for i = 1, #parts do
			if module:PartDividable(parts[i]) then
				local divided = module:SubdivdePart(parts[i], voxelSize)
				
				if not table.find(toweld,parts[i]) then
					table.insert(toweld,parts[i])
				end
				
				if not divided then 
					if callback then
						callback(parts[i])
						
						parts[i] = nil
						
					else
						parts[i]:Destroy()
					end
				end
			else
				
				parts[i] = nil
			end
		end
	until #parts == 0
	
	for c in toweld do
		if toweld[c] then
			weld(toweld[c])
		end
	end 
end

return module

this is the place:
Destruction System.rbxl (60.6 KB)

Hey there, I would like to help you but I can’t tell what your problem is just from this video. Could I see the script you used? Or at least that part that welds the negated objects together?

Could you please provide the code?
Its not possible for us to guess problem without you providing logic.

i have uploaded the file, Do you have a solution to my problem

I have found the solution. The welds were still applied to the clones.
Heres the fixed destruction system if anyone wants to use it
Destruction System Fixed.rbxl (60.6 KB)

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