Humanoid WalkToPoint being unresponsive

I want the player to be able to control an NPC by clicking around, but for some reason, the npc does not consistently follow the mouse. In this gif I am clicking rapidly, but the npc does not work as intended.

I’ve tried strictly setting the WalkToPoint to the mouse’s position, I’ve also tried using the Humanoid:MoveTo() function and currently I am using a method by ROBLOX I found on the wiki.

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)

event.OnClientEvent:Connect(function(t)
	if t[1] == "Control" then
		local npc = t[2]
		local shum = npc:FindFirstChild("Humanoid")

		local move = mouse.Button1Down:Connect(function()
			if mouse.Hit ~= nil then
				moveTo(shum, mouse.Hit.p)
			end
		end)
   end
end

You’re waiting 6 times to move the humanoid, so obviously it’s not working.

humanoid:MoveTo(targetPoint)
			wait(6)

Change it to

humanoid:MoveTo(targetPoint)
			humanoid.MoveToFinished:Wait()

As stated in my post, before I used the function I tried strictly setting the WalkToPoint and using MoveTo(). Meaning I did this:

local move = mouse.Button1Down:Connect(function()
			if mouse.Hit ~= nil then
				shum.WalkToPoint = mouse.Hit.p
			end
		end)
local move = mouse.Button1Down:Connect(function()
			if mouse.Hit ~= nil then
				shum:MoveTo(mouse.Hit.p)
			end
		end)

So the wait(6) is not the problem because these examples had the same result. I also tried the solution you mentioned and it still does not work as intented.

Well, it’s waiting clearly around 6 seconds, so I think you’re trouble is that

I’ve stopped using the ‘moveTo’ and changed the line of code to move the humanoid into this:

local move = mouse.Button1Down:Connect(function()
			if mouse.Hit ~= nil then
				shum:MoveTo(mouse.Hit.p)
			end
		end)

And the same problem remains, so I still don’t think the wait is the problem. However, I’ve noticed that after waiting a while it responds perfectly, do you possibly know why this might happen?