Humanoid.MoveToFinished fires before humanoid reaches part

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want an NPC to move to a part.

  2. What is the issue? Humanoid.MoveToFinished fires before the NPC actually reaches the part.

Here is the code I use:

local zombie = script.Parent
local humanoid = zombie.Humanoid

local point = workspace.Point

humanoid:MoveTo(point.Position)
humanoid.MoveToFinished:Wait()

print("finished moving")

here is a video of what happens:
https://gyazo.com/f22c589183743dec7bccfe27c93d97ac

  1. What solutions have you tried so far? I tried looking for solutions but found none. I don’t exactly know what the issue here is so that’s why Im asking for help on the devforum.
1 Like

I just tried this and I see not issue at all using what you tried.

EDIT: using

wait(1)

local zombie = script.Parent
local humanoid = zombie.Humanoid

local point = workspace.Point

humanoid:MoveTo(point.Position)
print("eeeee")
humanoid.MoveToFinished:Wait()

print("finished moving")

I know and that’s the problem. There is no issue with everyone else except for me

I apologize but what is the actual scripting issue. I tested this myself and “eeeee” was printed before “finished moving”

The actual issue is that the NPC doesn’t reach the part, unlike for other people, before MoveToFinished fires

From what I’m seeing zombie touches and reaches the part as said.

The same issue happens with me, I would make a value and then a function which changes the value every time the zombie reaches a part.

local zombie = zombie
local Part = Part
local Value = Value -- somewhere
local function ZombieMoveToFinished()
    Value.Value = Value.Value + 1
end)
zombie.Humanoid.MoveToFinished:Connect(ZombieMoveToFinished)
Value.Changed:Connect(function(property)
    if property == Value.Value then
        zombie.Humanoid:MoveTo(
            game.Workspace:WaitForChild(Part.Name..Value.Value) -- Part1, Part2
        )
    end
end)

hopefully this helps, not the actual script change the variable and names of Parts/Points :happy2:

It’s supposed to actually be exactly on the part…

So This si caused by the NPC going too slow ie the part are too far away,That movetofinished just skip and go do the next function,my fix is a repeat until loop that use a return function

local function Check(v)
	if (script.Parent.PrimaryPart.Position-v.Position).Magnitude > 4 then
		script.Parent.Humanoid:MoveTo(v.Position)
		script.Parent.Humanoid.MoveToFinished:Wait()
		print("Far From Position")
		return false
	elseif (script.Parent.PrimaryPart.Position-v.Position).Magnitude <= 4 then
		print("At the position")
		return true
	end
end

The 4 is a prevention of the HRP being above the part and still too far,You can reduce that to suit you

MoveToFinished has a default timeout of 8 seconds, there is sample code on the link below to bypass the timeout:
https://developer.roblox.com/en-us/api-reference/event/Humanoid/MoveToFinished

Was about to say this. Here is the code:

local function moveTo(humanoid: Humanoid, targetPoint: Vector3, 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

Thanks for all the help but I was able to solve it by using SimplePath and messing around with the code!