Having trouble with Moving NPC to part code

My goal: to make the “NPC” move to Part1
I used Roblox’s tutorial on it and fixed it so it matched my layout.
Here is the code:


local NPC = game.Workspace.NPC
local humanoid = NPC.Humanoid

local Part1 = game.Workspace.Part1
local Part2 = game.Workspace.Part2

humanoid:MoveTo(Part1.Position)


humanoid:MoveTo(Part2.Position)

Note: the NPC is unanchored.

Try moving the humanoidrootpart instead?

mm no it didn’t work hmm i’m not sure about this

Is there any errors?

30

No, I’ve checked the code countless times

I’ve tried using LocalScripts and Scripts.

It works on both local scripts and server scripts. Try it yourself.


local PATROL_DELAY = 2


local NPC = game.Workspace.NPC
local humanoid = NPC.Humanoid


local pointA = game.Workspace.Part1
local pointB = game.Workspace.Part2


local nextDestinationObject = pointA


while wait(PATROL_DELAY) do

	humanoid:MoveTo(nextDestinationObject.Position)

	
	humanoid.MoveToFinished:Wait()

	
	if nextDestinationObject == pointA then
		nextDestinationObject = pointB
	else
		nextDestinationObject = pointA
	end
end

In a Script

This script works, I just tested it. Make sure your NPC is fully unanchored.

Game File:
NPCMoving.rbxl (43.3 KB)

1 Like

Your npc’s humanoidrootpart may not be unanchored, because your script works fine for me

1 Like

Disregard my post about :MoveTo not working for humanoids in LocalScripts, I got confused and was referring to something else.

The only way I can replicate your issue on my side is if HumanoidRootPart anchored is set to true.