How to make Moving Mob more efficient?

Hello, current I have a script to move my enemy, but it is not efficient. It bugs out sometimes and I wanna see if there is a more better way of doing it, either by tween service or pivot. Can somebody help on how to make it more efficient?

function mob.Move(mob, map)
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.Waypoints

	for waypoint =1, #waypoints:GetChildren() do
		mob.MovingTo.Value = waypoint
		humanoid:MoveTo(waypoints[waypoint].Position)
		humanoid.MoveToFinished:Wait()
	end

	if humanoid.Health > 0 then
		HPInt.Value -= humanoid.Health
	end
	mob:Destroy()
end
1 Like

What do you mean by “more efficient”? Is the code slow? Does it use a lot of memory?

Could you send a video showing the bug?

By more efficient I mean that the code bugs a lot and is not smooth, like the enemy does not follow the path sometimes and goes off of it thats why I wanna learn how to maybe implement tween or piviot to this.

Sadly I can not show a video right now.

have you tried using the pathfindingservice? it is way more intelligent than moveto and you don’t need to place a waypoint every time you want a corner to be turned
https://developer.roblox.com/en-us/api-reference/class/PathfindingService