Humanoid:MoveTo() doesn't work as intended

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

  1. What do you want to achieve? Keep it simple and clear!
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
  • Magnitude check (still figuring it out)
  • Delaying movement time (failed)
  • Searched on the devHub (failed)
  • Extra checks (failed)
  • Rewatched the whole episode to figure out what I missed (failed, same code no problems)
  • Asked friend (busy or can’t find the solution)
function mobHandler.move(mob: Model, map: Folder)
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.waypoints
	
	local reached = false
	
	local testHUM = Instance.new("Humanoid")
	
	for waypoint=1, #waypoints:GetChildren() do
		humanoid:MoveTo(waypoints[waypoint].Position, waypoints[waypoint])
		humanoid.MoveToFinished:Wait()
  -- problem starts with these 2 lines↗
		print(waypoints[waypoint])
	end
	
	debris:AddItem(mob, .1)
	
	updateHealth:Fire(humanoid.Health) 
end

I heard humanoid movement systems have janky ahh movements and are very unreliable so I don’t mind if rewriting back the whole thing is the best option

2 Likes

In place of that line, use:

for _, waypoint in ipairs(waypoints:GetChildren()) do

The _ represents the index of the WP which you don’t use.

2 Likes

You also need to consider how your waypoints are going to be indexed. It might be better, just to create a table of the WPs Positions, ie:

local waypoints = {
	[1] = {1, 2, 5}
	[2] = {2, 2, 10}
	[3] = {3, 2, 20}
}

It depends on how each map loads the WPs, but they could al be kept in a large table, rather than having lots of parts for each

image
im pretty sure u dont need a second argument for MoveTo

edit: you’re also not checking if the waypoint exists using :GetChildren for waypoints (waypoints:GetChildren()[waypoint])

:moveto() has an 8 second expiration timer

I am pretty sure I only use waypoints[waypoint].Position tho

Well the problem is that i love parts and it is reliable for position indexing and i don’t have to write a ton of waypoint locations for any big map

This is the problem, keep calling MoveTo() until you actually reach the intended point.

for waypoint=1, #waypoints:GetChildren() do
	repeat
		humanoid:MoveTo(waypoints[waypoint].Position, waypoints[waypoint])
		humanoid.MoveToFinished:Wait()
	until (mob.PrimaryPart.Position - waypoints[waypoint].Position).Magnitude <= 1 -- u maybe need change 1 to smaller or bigger depend on enemy size
	print(waypoints[waypoint])
end
1 Like

Didn’t work. It stays stuck on point 1

change <= 1 to bigger number like <= 1.5

OMG IT WORKED TYSM!!!

Final edit: yes i did changed the numbers and it did worked

1 Like

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