Why does my :MoveTo() become lazy?

I feel like it’s a bug cause I was messing around with :MoveTo() and it seems like it is beacsue I made a whole new script and put it into to the enemy. The script it is:

local enemy = script.Parent
enemy.Humanoid:MoveTo(workspace.End.Position)

And it still does not go the full way. I have not used free models or anything it just does that by itself. I can show you proof here:
robloxapp-20211222-1348120.wmv (2.0 MB)

I’m actually gonna think that it’s a problem with the script instead. I think your MoveTo mechanism works perfectly, but the points are not ordered at all making them move to another point that they’re not intended to.

Here’s an example I just made using waypoints in a folder and just simply moving to each one.

Code Example
for _, part in pairs(workspace.Folder:GetChildren()) do
	rigHumanoid:MoveTo(part.Position)
	rigHumanoid.MoveToFinished:Wait()
end

ezgif.com-gif-maker

As you can see, the script works. But the logic is still not complete. Although it seems like its skipping, there’s no script determining which waypoint to move to FIRST, having the engine just order by itself.

There are two ways you can do this.

Order by distance
table.sort(waypoints, function(a, b)
	local aDistance = (a.Position - rigHumanoid.RootPart.Position).magnitude
	local bDistance = (b.Position - rigHumanoid.RootPart.Position).magnitude

	return aDistance < bDistance
end)

for _, part in pairs(waypoints) do
	rig.Humanoid:MoveTo(part.Position)
	rig.Humanoid.MoveToFinished:Wait()
end

This works very well, but you can see flaws that it could still ‘skip’ because one waypoint is actually closer than the other.

ezgif.com-gif-maker (2)

Order by number
table.sort(waypoints, function(a, b)
	return tonumber(a.Name) < tonumber(b.Name)
end)

for _, part in pairs(waypoints) do
	rig.Humanoid:MoveTo(part.Position)
	rig.Humanoid.MoveToFinished:Wait()
end

This works just as well as the first one, but it is ideal if you want it to walk in a specific path, being the perfect method that can be utilized for the game.

ezgif.com-gif-maker (1)

I will attach a place file of this game that shows how each method works, you can find the script inside of the Dummy in the workspace.
Movement Example.rbxl (32.6 KB)

Try numbering your waypoints from closest to furthest (1 to x) and use this in your script and see how it works;

function mob.Move(enemy, map)
	local humanoid = enemy.Humanoid 
	local waypoints = map.WayPoints:GetChildren()

	table.sort(waypoints, function(a, b)
		return tonumber(a.Name) < tonumber(b.Name)
	end)

	for _, waypoint in pairs(waypoints) do
		humanoid:MoveTo(waypoints[waypoint].Position)
		humanoid.MoveToFinished:Wait()
	end
end

Mark as solution if this helped you! A little off topic; but a very cool project you’re making. I wish the best of luck :grinning_face_with_smiling_eyes:

I just found out it’s not a bug not a problem with my script. Roblox set an 8 second timeout on :MoveTo(). But thank you for trying to help me :slight_smile:

1 Like

hehe it’s time to use the good old position magnitude again

1 Like