Humanoid:MoveTo() not running on NPC

On a local script, I use Humanoid:MoveTo(), on an NPC’s character.

What I want to do is make

  1. My character moving to Point A
  2. NPC’s character moving to Point B
  3. Both at the same time.

However, everytime,
my character will move, and the NPC’s character will not.

I have absolutely no clue on what’s causing this. What makes it even more baffling, is that there would be a very small % chance that the NPC will move. It’d say about 2% of the time. (What I did was use the same code to test again and again)

Here’s the script for reference.

local function WalkToPoint(character,MovePoint) --MovePoint is the Vector3 itself
	
	--// Create the path first
	local waypoints = MakePathRemoteFunction:InvokeServer(character.PrimaryPart.Position,MovePoint)
	
	if not waypoints then
		error("Waypoints not found")
		return
	end
	
	if not character.Humanoid or not character.Humanoid.Animator then
		error("FUNCTION: WalkToPoint has stopped due to character not having a humanoid OR/AND an animator in the humanoid.")
		return
	end

	for i, v in pairs(character.Humanoid.Animator:GetPlayingAnimationTracks()) do
		v:Stop()
	end

	local connection

	local newAnimation = Instance.new("Animation")
	newAnimation.AnimationId = "rbxassetid://913376220" --3570535774 913376220
	newAnimation.Name = "RunningAnimation"
	newAnimation.Parent = character

	local walkAnim = character.Humanoid:FindFirstChild("Animator"):LoadAnimation(newAnimation)
	walkAnim:Play()

	local NextWaypointIndex = 2
	
	print(waypoints,character)
	character.Humanoid.WalkSpeed = 16
	
	for i, v in pairs(waypoints) do
		print(character, v.Position)
		connection = character.Humanoid.MoveToFinished:Connect(function(reached)
			
			print(reached)
			if reached and NextWaypointIndex < #waypoints then
				NextWaypointIndex += 1
				print("CHARACTER", character, "MOVED TO THE NEXT POINT")
			else
				print("Finished for character", character)
				walkAnim:Stop()
				character.Humanoid.WalkSpeed = 16
				newAnimation:Destroy()
				if connection then
					print(NextWaypointIndex, #waypoints)
					connection:Disconnect()
					connection = nil
				end
			end
		end)
		
		character.Humanoid:MoveTo(v.Position)
	end
	
	character.Humanoid.WalkSpeed = 16
	character.Humanoid:MoveTo(MovePoint)
	
	

I have checked and confirmed that:

  • Humanoid Speed is not set to 0.
  • Character parts are unanchored.
  • Waypoints exists.
  • All print statements printed.
  • No errors in the Output.

Feel free to ask further questions, if I had not clarified anything clearly.
Thanks for taking your time out to read this. I appreciate it.

2 Likes

I dont know much about networkowner ship but if youre moving them on a local script then from what I read networkowner ship over the character goes to someone who is near the npc and also the nearest, if the player does not have ownership over the npc then he cannot edit or move the npc in any way.

read more about it here:
Network Ownership.

To solve the problem you could use BasePart:SetNetworkOwner
to the player then edit the npc

Think I may have run into something similar. If the NPCs HumanoidRootPart is anchored, try setting to unanchored and see if you get diff results.

I didn’t do anything about NetworkOwnership, but that did gave me an idea to work it out.

What I did was that I made sure that the NPC is local to the player. That’s it. And it worked. (It’s kinda similar to basepart:SetNetworkOwner)

(I cloned the NPC and parented the original NPC to nil)

Thanks

1 Like