I have a script inside an NPC's HumanoidRootPart which is supposed to check if a player hit the NPC and that makes the NPC follow him. Here it is:
function onTouched(hit)
if script.Parent.Parent.Humanoid.Health < 100 and hit.Parent.ClassName == 'Tool' then -- checks if it's a tool and if the NPC has been damaged
script.Parent.Value.Value = true -- don't mind that
while hit.Parent.Parent.Parent.Humanoid.Health > 0 do -- checks if player is still alive
wait(.5)
script.Parent.Parent.Humanoid:MoveTo(Vector3.new(hit.Parent.Parent.HumanoidRootPart))
end
end
end
script.Parent.Touched:connect(onTouched)
However, it didn't seem to work so I made the script print the hit.Parent.Parent.Name to check if I was actually targeting the character and sometimes it gives me my character name, other times Workspace and other times backpack. Is there any way to fix this?
Also, I'm unsure if the WalkTo works.

2 comments
ok so
so i did a quick test in studio with your script and the first problem I found is that on Line 4 you say hit.Parent.Parent.Parent that is you put dot parent 3 times which explains why it gave you workspace hit.Parent is the tool the parent of that is the character model if you add another dot parent, you get an error saying HumanoidRootPart is not a valid member of Workspace, so that is a problem