GetTouchingParts not working as intended?

I’ve put together a weld script to weld all touching parts in my game. The problem is, that’s… not actually working. I’m using :GetTouchingParts, but that only appears to be getting parts inside of each other. If you need the code, here it is:

function Weld:WeldAllParts(model)
print(“Welding…”)
for _, child in pairs(model:GetDescendants()) do
if child:IsA(“BasePart”) and not child:IsA(“Terrain”) then
for _, touchingPart in pairs(child:GetTouchingParts()) do
local isWelded = false

			for _, weld in pairs(touchingPart:GetChildren()) do
				if weld:IsA("WeldConstraint") then
					if weld.Part0 == child and weld.Part1 == touchingPart or weld.Part0 == touchingPart and weld.Part1 == child then
						isWelded = true

						break
					end
				end
			end

			if not isWelded then
				local weld = Instance.new("WeldConstraint")

				weld.Part0 = child
				weld.Part1 = touchingPart
				weld.Parent = child
				weld.Enabled = true
			end
		end
	end
end

end

This is at the point where even the BASEPLATE isn’t being welded to. Only parts inside of each other are welded, but not if they’re actually touching! Is there any fix for this?

EDIT: The model is being set to workspace for now.

I have no idea how intensive this would be, but could you create a Region3 that is slightly larger than the size of the part, and get all parts within it? Maybe this would solve the issue of adjacent parts not being recognized.

2 Likes

I’ll try that. The map will be reloaded every, maybe 20 or so minutes, so loading time shouldn’t be a problem for re-welding.

1 Like

This appears to work well enough. Surprisingly, there is little to no lag on startup! I’ll leave this up though, in case someone has a better idea.

1 Like