WARNING: NOT THE PRETTIEST CODE IM JUST TRYING TO LEARN HOW TO USE THE PathfindingService
So the problem is with the MoveTo on the followPath function on line 37
local pathFindingService = game:GetService("PathfindingService");
local path = pathFindingService:CreatePath();
local NPC = script.Parent;
local NPC_Humanoid = NPC.Humanoid;
local waypoints;
local currentWaypointIndex;
local function findNearestPlayer(position)
local lowest = math.huge;
local nearestPlayer;
for _, v in pairs(game.Players:GetPlayers()) do
if v then
if v.Character then
local distance = v:DistanceFromCharacter(position);
if distance <= lowest then
lowest = distance;
nearestPlayer = v;
print(nearestPlayer.Name.." is closest player at a distance of :".. distance );
return nearestPlayer;
end
end
end
end
end
local function followPath(player)
path:ComputeAsync(NPC.HumanoidRootPart.Position, player.Character.HumanoidRootPart.Position);
waypoints = {};
if path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints();
print("lets see if i did a thing");
currentWaypointIndex = 1;
NPC_Humanoid:MoveTo(waypoints[currentWaypointIndex].Position);
print("now it should be moving");
else
NPC_Humanoid:MoveTo(NPC.HumanoidRootPart.Position);
end
end
local function onWaypointReached(reached)
if reached and currentWaypointIndex < #waypoints then
currentWaypointIndex = currentWaypointIndex + 1;
NPC_Humanoid:MoveTo(waypoints[currentWaypointIndex].Position);
end
end
local function onPathBlocked(blockedWaypoint)
if blockedWaypoint > currentWaypointIndex then
local nearestPlayer = findNearestPlayer(NPC.HumanoidRootPart.Position);
followPath(nearestPlayer);
end
end
while true do
wait(15);
local nearestPlayer = findNearestPlayer(NPC.HumanoidRootPart.Position);
if nearestPlayer then
followPath(nearestPlayer);
end
end
path.Blocked:Connect(onPathBlocked)
NPC_Humanoid.MoveToFinished:Connect(onWaypointReached)
It does change the WalkToPoint but the NPC (Clone of my character from in game) does not actually walk to that point I can't figure out why
Here is the WalkToPoint before MoveTo was called
also sorry for hurting your eyes with this ugly code I just want to figure this out I have been stuck for almost a day now .-. It worked like twice then it just stopped working.

5 comments
alvinbloxx taught me put a wait at the top of my script so try that
Shut up incapaz
Are any of the parts in the character anchored? The humanoid's walkspeed is not 0 and PlatformStand is off, right?
Nope, 16 and yes
@ScriptingEngine