NPC Humanoid does not listen to Vector3 I give it

  1. My goal
    I want to make my NPC move, using :MoveTo()
    image

  2. The issue?
    The NPC suddenly stops.

The red Part represents the position I gave it.


I do not understand why it stops there.

  1. Solutions I’ve tried
    I’ve checked other scripts, the humanoid itself, invisible walls… Everything. It fires MoveToFinished() when it gets there. I’ve even tried testing and making it go to (10,10,10) and it STILL stops somewhere close to that.

This is the position is stops at

45.807, 3, -118.195

I’m going crazy over this. Please help!

:MoveTo() has a 8 second timeout
use this function i stole from the roblox docs:

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(reached)
		end
	end)

	-- start walking
	humanoid:MoveTo(targetPoint)

	-- execute on a new thread so as to not yield function
	task.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)
			task.wait(6)
		end

		-- disconnect the connection if it is still connected
		if connection then
			connection:Disconnect()
			connection = nil
		end
	end)
end

local function andThen(reached)
	print((reached and "Destination reached!") or "Failed to reach destination!")
end

moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)

src: Humanoid | Documentation - Roblox Creator Hub

This should be written in BIG BOLD RED TEXT somewhere. I’ve legit been trying to bugfix for the past hour. You are a lifesaver, thank you!

Btw, doesn’t that mean that using that function would return MoveToFinished multiple times? I would like to yield until the NPC finished moving.

Anyways, I will figure the function/solution on my own. Thank you for the info again, I will mark as solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.