Humanoid MoveTo() Ending before destination

Making NPCs all moves the same point (the part in the gif), however they always stop before reaching the end destination for no know reason.

gif:
https://gyazo.com/2c21a7cb7c9010e628341c1d6989fc1a

code:

function RetargetGroup(Group)
	for i,v in pairs(Group.Members) do
		v.Humanoid:MoveTo(Group.CurrentTarget)
	end
end
1 Like

Are you using while true do? If not then that could be the problem.

Why would I use a while true do? the target is not changing at the moment for testing purposes. Using a while true do Is an unnecessary method which would damage performance.

Yeah but the :MoveTo() function is kinda weird. That has also happened to me, then I used while true do and it fixed. I would recommend you to at least try using it.

Sorry, but id rather a different solution since looping the MoveTo() is not really a solution id like to resort to.

I see, I will try to help you using any other solution.

1 Like

Ok probably this? Not sure if it will work.

local Torso = script.Parent:WaitForChild("Torso")
local Velocity = Torso.Velocity

Torso.Changed:Connect(function()
     if Velocity.Magnitude < 3 then -- If the entity is not moving
          -- Repeat the MoveTo function
     end
end

Ok that is definitely a plausible backup plan if there as no solutions as to why MoveTo() is not behaving as expected, thanks!

1 Like

No problem! Good luck with your NPCs.

1 Like

In the description for Humanoid:MoveTo there is a paragraph with:

The reach goal state of a humanoid will timeout after 8 seconds if it doesn’t reach its goal.

So most likely, your humanoids do not reach their “goal” within that ‘timeout’.

Try see if the code sample on that developer.roblox.com page can be of help / inspiration.

3 Likes

Yeah basically the easiest way to fix this issue is using a while true do loop.

For the purpose of archive, here is the solution I found best and am currently using

function RetargetGroup(Group, Checks)
	Group.Arrived = false
	for i,v in pairs(Group.Members) do
		local Position = GetRandomInPart(Group.CurrentTarget).p
		local Check = 0
		v.Humanoid:MoveTo(Position)
		Func = v.Humanoid.MoveToFinished:Connect(function()
			Check = Check + 1
			if Check == Checks then
				Func:Disconnect()
			else
			    v.Humanoid:MoveTo(Position)
			end
		end)
	end
end

Basically you give an estimate of segments of 8s it will take for the humanoid to reach the target (always over estimate) then when that estimate is reached it cancels the moveto