game.Players.PlayerAdded:connect(function(Player)
local p = game.Workspace:WaitForChild(Player.Name)
print (p)
local f = p.UpperTorso.Position
print (f)
local dist = 15
local pos1 = f
for i,v in pairs(game.Workspace.CrystalMobA.UndeadWarrior:GetChildren())do
if v.Name == "HumanoidRootPart" then
print (v)
local z = v.Parent.Humanoid
local pos2 = v.Position
local magnitude = (pos1 - pos2).magnitude
if magnitude <=15 and z then
if p.Humanoid ~= nil then
print('humanoid')
while true do
wait(1)
local target = f(v.Position)
if target ~= nil then
print ("Following")
v.Parent.Humanoid:MoveTo(target.Position, target)
end
end
end
end
end
end
end)
COMMUNITY QUESTION
Issue with Getting NPC to follow. Error start at print(Humanoid)? Above this print works
0 answers
No public answers were preserved for this question.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Line 2 is a bad way of getting the character, what if the characters name was "Part" OOF RIP
Literally, everybody starting out to script gets their character this way. It's not wrong, but it's very inefficient. A Player object has a property called 'Charcater.' this property is your character, so to get the character, you just have to 'local p = Player.Character'
Also, you probably don't need the (v.Position) at line 19, local target = f(v.Position). I think it'll work if you just remove (v.Position).