Hello. I'm making a game with NPCs. I figured out how to make some move, but now, they don't go to the part I want them to. There are ZERO SCRIPTS that make them detect the player. I inserted a Dummy from the rig builder, unanchored everything, and customized it. The only script that makes them move is the script that includes the MoveTo(). I need some help on this.
Any working answer is appreciated.
COMMUNITY QUESTION
NPC Only moves to where the player is, not to the part I told it to go to?
1 answer
Do you have any script samples?
Do you want it to go to BOTH the player and the part?
The script below allows the NPC to go to the part with the use of :MoveTo()
local PFS = game:GetService("PathfindingService")
local NPC = workspace.NPC --replace with your npc
local humanoid = NPC:FindFirstChild("Humanoid")
local destination = workspace.Destination --replace with the part that you want to NPC to go to
local path = PFS:CreatePath()
path:ComputeAsync(NPC.HumanoidRootPart.Position,destination.Position)
local waypoints = path:GetWaypoints()
for i, v in pairs(waypoints) do
humanoid:MoveTo(v.Position)
humanoid.MoveToFinished:Wait()
end
If you want them to detect a player as well, replace the NPC with your character.
If you want them to detect the nearest player, use Magnitude and a while true do loop
to constantly search for the nearest player. Then, compute the path and move their humanoid to the waypoints.
Here's the Pathfinding article that you might find useful
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
waypoint on line 14 is higlighted in red, unless you meant waypoints instead? But however, trying both of these, I get two different error outputs. If I use waypoints, I get "Argument 1 missing or nil" if I use just waypoint, as in your script, I get "ServerScriptService.Script:20: attempt to index nil with 'Position'
Oops, sorry. I fixed it.
I'll try it out.
This still did not work. My other script where it has MoveTo did make it move, but not this one. Everything in the NPC is unanchored.
Also note, that I'm using a BindableEvent. You can learn more about my script here: https://scriptinghelpers.org/questions/123692/npc-wont-move-to-the-position-i-want-it-to