GetTouchingParts not working?

Hello I am working on a plugin to weld ONLY touching parts on a selected model. Although I have come across an issue with the “GetTouchingParts()” function. Here is what I have done so far. It originally was working fine until I decided that the code wasn’t running right so I modified it and since then it didn’t work. (Yes the parts are anchored and yes the .CanCollide and .CanTouch values on them are enabled.

local Table = Part:GetTouchingParts() -- Doesn't work
-----------------------------------------------------------------------
function getTouching(part)
	local signal = part.Touched:Connect(function() end)
	local touching = part:GetTouchingParts()

	signal:Disconnect()

	return touching
end
local Table = getTouching(Part)

Here is my full code for all to see.

local Toolbar = plugin:CreateToolbar("Weld Touching Parts")
local PluginButton = Toolbar:CreateButton("Weld Touching Parts", "Weld all touching parts under the selected model", "http://www.roblox.com/asset/?id=12869498959")

function WeldSelected()
	print("Ran function")
	local SelectedModel = game:GetService("Selection"):Get()[1]
	if SelectedModel == nil or not SelectedModel:IsA "Model" then return end

	print("Selected isn't nil ;0")

	for _, Part in pairs(SelectedModel:GetDescendants()) do
		print("Doing i,v loop.")
		if Part:IsA "BasePart" then
			print("oh em gee part is a basepart?!")
			local Table = Part:GetTouchingParts()
			if Table ~= nil then
				for i, TouchingPart in pairs(Table) do
					print("Doing second i,v loop.")
					if TouchingPart:IsA "BasePart"  then
						print("oh em gee TouchingPart is a basepart?!")
						if TouchingPart.Anchored == true then TouchingPart.Anchored = false end
						local Weld = Instance.new("WeldConstraint")
						Weld.Part0 = Part
						Weld.Part1 = TouchingPart
						Weld.Parent = Part
					end
				end
			end
		end
	end
end

PluginButton.ClickableWhenViewportHidden = true

PluginButton.Click:Connect(function()
	WeldSelected()
end)```

I here is the output btw, it only get’s to the i,v loop furthermore proving that Part:GetTouchingParts() isn’t working for some odd reason.
image

You could probably debug more effectively here making it easier for you and for us trying to help

You could start by printing what GetTouchingParts() returns

Already did that, it returns as nil and or empty.
image

Well either way GetTouchingParts is obsolete as is replaced by more performant APIs that do not require you to connect an empty function

Some of these allow you to detect parts overlapping a certain box. You’ll just have to create an overlay box that has the same properties that the part you are measuring does.

But NONE of those do anything I want to do. I want to fetch all touching parts and weld the touching parts to each-other. Those functions are more for region3 and raycasting.

Did you even read the post? They literally do the exact same thing except :GetTouchingParts isn’t used so no stupid cache.


local function getTouchingParts(corePart)
  local overlapParams = OverlapParams.new()
  overlapParams.FilterType = Enum.RaycastFilterType.Blacklist
  overlapParams.FilterDescendantsInstances = {corePart}

  return workspace:GetPartsInPart(corePart, overlapParams)
end

GetPartsInPart also takes into effect the geometry of any custom shape (meshes, shapes etc) the part may have for both the core and touching parts
You can add overlapParams.RespectCanCollide to ignore parts that have CanCollide off, CanQuery also effects this but cannot be toggled.
GetPartsInPart
OverlapParams

Still returns as an empty table. I did read it and GetPartsInPart is mainly for parts colliding within each other not just hitboxes touching.

Try checking the collision configurations of the part, one or other may make it impossible to touch the part itself.

I feel like the reason for the script to return nothing is most likely due to the actual geometry of models not touching.

The parts are on top of each other no gaps or anything.
image

This might be because the part isn’t in the part, since it’s on top. You can try using GetPartBoundsInBox and pass in the CFrame and slightly increase the size.

First things first, :GetTouchingParts will only collect parts which are inside of the part which the function was called from. This means that even if the original part is ‘touching’ other parts it won’t collect them because the parts need to be at least 0.001 inside of the original part. Correct me if I’m wrong on that, but that’s from experience. Try move one of the parts even a little tiny bit inside the original part.