Why I can't move my npc with the MoveTo() method?

I have a NPC which looks like a panda and has its humanoid,named “p0-abao” and parented to workspace.I read the article :“Character Pathfinding | Documentation - Roblox Creator Hub” and use the demo code as blow:

local PATROL_DELAY = 2
 
-- Variables for the zombie and its humanoid
local zombie = game.Workspace["p0-abao"]
local humanoid = zombie.Humanoid
 
-- Variables for the point(s) the zombie should move between
local pointA = Vector3.new(-398.8, -61.5, -509.6) --game.Workspace["Part111"]
local pointB = Vector3.new(-418.6, -61.7, -535) --game.Workspace["Part222"]
 
-- Variable to keep track of the zombie's next destination
local nextDestinationObject = pointA
 

-- Loop to move between the two points
while wait(PATROL_DELAY) do
	humanoid:MoveTo(nextDestinationObject)
 
	-- Wait until the zombie has reached its target
	humanoid.MoveToFinished:Wait()
 
	-- Switch the current target to the other target
	if nextDestinationObject == pointA then
		nextDestinationObject = pointB
	else
		nextDestinationObject = pointA
	end
	
end

I place these codes in a script under the ServerScriptService.
but my NPC don’t move and no error message in the output window.WHY?

Thx a lot

I copy and pasted the script and it worked fine, I would make sure:

  1. The NPC is entirely unanchored
  2. The script is not Disabled
  3. The NPC has a WalkSpeed > 0
5 Likes

Make sure the HumanoidRootPart is unanchored. It solved a lot of similar problems like this for me in the past.

4 Likes

Thx ! It’s worked.

By the way ,how can I set the walkSpeed for my NPC?It is a group with many parts.I didn’t find property like "walkspeed " of it.

There is a property called humanoid.WalkSpeed (in the NPC’s humanoid) that you can change.

2 Likes

Got it :+1: