Pathfinding moving in circles

Firstly: I am trying to learn how to make fighting npc’s so I have no idea if pathfinding is even the right way, I dont really want to watch a tutorial for it because I want to learn it not copy-paste it.

so, I have built this pathfinding system
but randomly the npc’s move in circles

I have looked for posts but never found one that has a solution.

I have tried:
using lookat() then moving by one stud – caused way too glitchy movement
changing agent settings – did nothing
reading forums – did nothing (none had solutions)

The problem might be but I do not know how to fix:
I shouldnt be using pathfinding
I am overriding paths – (idk just saw that in a post)
Roblox’s pathinding is bad

the following code is not the full script, although I will note it’s inside a wait() loop,
hrp is the npc’s root part and item is the targets root part.

		local path = pfs:CreatePath({
			AgentRadius = 3,
			AgentHeight = 6,
			AgentCanJump = false
		})
		local success, errorMessage = pcall(function()
			path:ComputeAsync(hrp.Position, item.Position)
		end)
		script.Parent.Humanoid:MoveTo(path:GetWaypoints()[2].Position, hrp)

edit: using any form of wait() makes it consistently move in circles

thanks!

Why do you let the NPC walk always to the Waypoint 2 calculated by the path?

 script.Parent.Humanoid:MoveTo(path:GetWaypoints()[2].Position, hrp) -> path:GetWaypoints()[2]

I normally loop trough all waypoints and let the NPC walk to Waypoint 1, then 2 and so on.

whenever I used 1 it didn’t move at all

You should use something like a loop and not one static Number since there could be multiple waypoints and not just one to go trough. It could looks like this:

local success, errorMessage = pcall(function()
  path:ComputeAsync(hrp.Position, item.Position)
end)
if not success then warn(errorMessage) return end

local Waypoints = path:GetWaypoints()

if Waypoints then
  for i, waypoint in ipairs(Waypoints) do
    script.Parent.humanoid:MoveTo(waypoint.Position)
    script.Parent.humanoid.MoveToFinished:Wait()
  end
end

yeah I already tried that, it makes the circular movement worse but I believe I have found the fix to it either way but im still testing it

So it seems after a day and looking back on my code I don’t think I needed to pathfind, my new code is just script.Parent.Humanoid:MoveTo(item.Position, hrp) via moving to the targets root itself but making the npc a bit dummer which is good enough for my standards

nevermind, its a moveto() problem i guess