What could be the potential reason why I can't get the parts touching this models PrimaryPart

I have a temporary model that follows the players cursor. When the player tries to place this temporary part I try to do a check to see if the TemporaryPart is touching the Baseplate or Terrain.

The problem that I’m having is I cant seem to get a table of the parts touching the TemporaryModels PrimaryPart. At the very least the other parts in the model touching the PrimaryPart should be in the table but they are not.

I have no idea why this table always returns with nothing. Any solutions or potential feedback would be appreciated. Thanks in advance.

--Code snippet

						local touchingParts = Temporary_Model.PrimaryPart:GetTouchingParts()
						local partsTable = {}

						for _, part in ipairs(touchingParts) do
							table.insert(partsTable, part)
						end
						
						if #partsTable > 0 then
							for a, b in ipairs(partsTable) do
								print(b)
							end
							else print("no parts in table!")
						end

[[-----OUTPUT-----
  20:32:54.083  no parts in table!  -  Client - LocalScript:343
]]

First, set up a Touched connection.
Then use GetTouchingParts
Then disconnect your Touched connection

local touchingParts = {}

for _,v in Temporary_Model:GetChildren() do
    if not v:IsA("BasePart") then
        continue
    end

    local connection = v.Touched:Connect(function() end)

    for _, part in v:GetTouchingParts() do
        table.insert(touchingParts, part)
    end
    
    connection:Disconnect()
end
1 Like

it is possible that this is your problem

If the part itself has CanCollide set to false, then this function returns an empty table unless the part has a TouchInterest object parented to it (meaning something is connected to its Touched event)

as the documentation suggests, you can try WorldRoot:GetPartsInPart(). Or maybe WorldRoot:GetPartBoundsInBox() or WorldRoot:GetPartBoundsInRadius() which are more efficient.

1 Like

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