:GetTouchingParts() cannot find character

I’ve been trying to make it possible for players to be standing in a monorail I’m designing. To achieve this, I want to create a WeldConstraint between every character touching the floor of the Train Car and the floor itself.

The problem I found is that when running :GetTouchingParts() on the floor, it never returns any part found in a character.

To note that I did find this in the documentation: Parts that are adjacent but not intersecting are not considered touching. . As I used this function to weld pallets to a truck bed before succesfully, I initially didn’t give it any attention. After the script failing to work, I attempted to set the floor to CanCollide = false then back on to get the players to stick their legs inside a bit. Still no success.

Any solutions on how I can get this function to return me body parts, or maybe alternatives?

2 Likes

Do you want these players to move? If so, a WeldConstraint won’t help as it locks an object in place relative to another object.


Otherwise, you shouldn’t need GetTouchingParts for this. Create a collision box (an invisible part with CanCollide disable) and subscribe to the Touched and TouchEnded event. Specifically you want to listen to touches involving a ‘HumanoidRootPart’. When this happens, you can go ahead and add them to your list of ‘HumanoidParts’ inside of the collision box then create welds when necessary.

For example:

local collisionBox = ...
local humanoidParts = {}

collisionBox.Touched:Connect(function (hit)
  if hit.Name == "HumanoidRootPart" then
    humanoidParts[hit] = true -- we use a dictionary keyed on the part to prevent duplicates
  end
end)

collisionBox.TouchEnded:Connect(function (hit)
  humanoidParts[hit] = nil -- we don't need to check if the part exists, this just removes it from the dictionary if it does exist
end)

Then to iterate through the parts:

for humanoidPart, _ in pairs(humanoidPart) do
  -- perform weld
end
2 Likes