Humanoid MoveTo() doesn't work

https://gyazo.com/55062c164c4661305bb21f4737ffc711
https://gyazo.com/9d619c9b38f4a96d987125d96478842f


local function moveTo(humanoid, targetPoint, andThen)
	local targetReached = false
 
	-- listen for the humanoid reaching its target
	local connection
	connection = humanoid.MoveToFinished:Connect(function(reached)
		targetReached = true
		connection:Disconnect()
		connection = nil
		if andThen then
			andThen()
		end
	end)
 
	-- start walking
	humanoid:MoveTo(targetPoint)
 
	-- execute on a new thread so as to not yield function
	spawn(function()
		while not targetReached do
			-- does the humanoid still exist?
			if not (humanoid and humanoid.Parent) then
				break
			end
			-- has the target changed?
			if humanoid.WalkToPoint ~= targetPoint then
				break
			end
			-- refresh the timeout
			humanoid:MoveTo(targetPoint)
			wait(6)
		end
		
		-- disconnect the connection if it is still connected
		if connection then
			connection:Disconnect()
			connection = nil
		end
	end)
end

moveTo(workspace.PatroByteNPC.Humanoid, workspace["Walk Here"].Position, print("lol"))

The NPC only moves when I move, is this a bug or a problem with my code?

Found the solution, I was moving it locally which is why it was choppy. I changed it to server and it works fine.