How could I make a weld script which welds by welding the parts that are touching eachother

I want a script which welds parts by check what parts are touching each other and then welding them each other. I have been trying to figure out how I can do this but it has not been working. Please help

1 Like

You can just use BasePart.Touched and then add an if statement to check if it’s a part that is touching it and not a player.

workspace.Part1.Touched:Connect(function(hit)
if hit.Name = "ConnectionParts" then -- Findind to see if it's the right part

local Weld = Instance.new("WeldConstraint")
Weld.Parent = workspace.Part1
Weld.Part0 = hit
Weld.Part1 = workspace.Part1

end
end)
2 Likes

I editied the script like this so then it happens with all parts in a model, however I don’t know how to fix the new positions made from the parts due to them being unanchored.

Nevermind, I found the solution. Thanks for the help!

local part = workspace:WaitForChild("Part")

part.Touched:Connect(function(hit)
	if not part.Anchored or not hit.Anchored then
		return
	end
	local weld = Instance.new("Weld")
	weld.Parent = part
	weld.Part0 = part
	weld.Part1 = hit
end)