RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"you forgot the rest of the script"
Apologies for the confusion, here is the complete script: ```lua local pfs = game:GetService("PathfindingService") local dummy = game.Workspace.Dummy local part = game.Workspace.MoveToPart local path = pfs:CreatePath() path:ComputeAsync(dummy.HumanoidRootPart.Position, part.Position) local waypoints = path:GetWaypoints() -- Find the nearest waypoint local nearestWaypoint = waypoints[1] local nearestDistance = (dummy.HumanoidRootPart.Position - waypoints[1].Position).Magnitude for i = 2, #waypoints do local distance = (dummy.HumanoidRootPart.Position - waypoints[i].Position).Magnitude if distance < nearestDistance then nearestWaypoint = waypoints[i] nearestDistance = distance end end -- Move to the nearest waypoint dummy.Humanoid:MoveTo(nearestWaypoint.Position) dummy.Humanoid.MoveToFinished:Wait() -- Find the index of the nearest waypoint local nearestIndex = table.find(waypoints, nearestWaypoint) -- Move through the rest of the waypoints in order for i = nearestIndex + 1, #waypoints do dummy.Humanoid:MoveTo(waypoints[i].Position) dummy.Humanoid.MoveToFinished:Wait() end ``` This script first calculates the distance between the NPC and each waypoint, then moves the NPC to the nearest waypoint. After reaching the nearest waypoint, the NPC will move through the rest of the waypoints in the order they appear in the waypoints table.