Why is :GetTouchingParts() not working on children of my NPC but working on another NPC?

In my script that finds if the building is being touched.

local Part = script.Parent.TouchBox
local Attacked = script.Parent.Attacked
local Health = Part.Parent.Health
local Found = Instance.new("NumberValue", Part)
Found.Value = 0

while Attacked ~= nil do
    wait(1)
	Found.Value = 0
	local Parts = Part:GetTouchingParts()
	for i,v in pairs(Parts) do
		if v.Parent.Name ~= "Tub" and v.Parent.Name ~= "Workspace" then
	    if v.Parent.Name == "Brute" then
		print("Brute Touching")
		Found.Value = Found.Value + 1
		Attacked.Value = true
	else
		print("Nope")
		print(Found.Value)
		print(v.Name, v.Parent.Name.. " is this one's parent!")
	    end
	end
	end
	wait(0.2)
	if Found.Value == 0 then
		Attacked.Value = false
		print("Not Being Attacked")
	end
end

I’m testing it with two different NPCS. One made by me and another one that is default.

Properties of Left Hand of my NPC

bandicam%202019-05-04%2006-13-49-888

if v.Parent.Name == “Brute” then

Is not detected when touched.

Properties of Left Hand of other NPC

(Is normally unanchored)bandicam%202019-05-06%2002-01-22-590

if v.Parent.Name == “John Doe” then

Is detected when touched.

So I’m not sure if it’s an issue with their properties causing :GetTouchingParts() to not work or an issue with my script. Please help because this is very confusing

1 Like

The parts their parent might not be as a child of the brute? (Is a child of a different body part) causing it to check that one’s parent, you could also try using this on just the humanoidrootpart instead of the others parts. Not sure if you want it to be like that but it’s a good try to see if it even reacts to just the humanoidrootpart

CanCollide on your other NPC’s Left Hand has to be enabled for :GetTouchingParts() to return it.

If you need that part to have CanCollide disabled, I recommend checking out this post by buildthomas.

2 Likes