local players = game:GetService("Players"):GetChildren()
local target
local nearest = {}
local movemessage = "The parent humaniod has tried to move, but unfortunately might've failed."
while wait() do
for i = 1,#players do
local distance = (script.Parent.Torso.Position-players[i].Character.Torso.Position).magnitude
if distance <= 20 then
table.insert(nearest,1,players[i].Character.Torso.Position)
table.sort(nearest,#nearest)
target = nearest[1]
else
return
end
end
end
local debounce = false
while wait(2) do
walktoplayer()
end
function walktoplayer()
if target ~= nil and debounce == false then
debounce = true
local path = game:GetService("PathfindingService"):FindPathAsync(script.Parent.Torso, target)
local points = path:GetWaypoints()
for i,v in pairs(points) do
local stud = Instance.new("Part", workspace)
stud.Anchored = true
stud.CanCollide = false
stud.CFrame = CFrame.new(v.Position)
stud.Size = Vector3.new(1,1,1)
end
if path.Status == Enum.PathStatus.Success then
for i,v in pairs(points) do
script.Parent.Humanoid:MoveTo(v.Position)
print(movemessage)
script.Parent.Humanoid.MoveToFinished:Wait()
if v.Action == Enum.PathWaypointAction.Jump then
script.Parent.Humanoid.Jump = true
end
end
end
debounce = false
end
end
Doesn't even print the movemessage. What's the issue?

1 comment
Maybe try making the NPC to go to the HumanoidRootPart, not the Torso.