MoveToFinished() fires after the CFrame of the humanoidRootPart is set to look at the player

I want to make it so the NPC always looks at the player when they’re in line of sight

The issue is that, when setting the NPC’s cframe with CFrame.LookAt, MoveToFinished() fires instantly without actually reaching the waypoint + it also stops the NPC’s movement.

Video clip of the issue:

External Media

You can also see how at the output it prints which waypoint it’s currently moving to.
And the function I use to make the NPC look at the player is this:


function lookAt(target)
	
	if workspace:FindFirstChild("PixelRankYT") then
		local lookAtPos = Vector3.new(workspace.PixelRankYT.HumanoidRootPart.Position.X,script.Parent.HumanoidRootPart.Position.Y,workspace.PixelRankYT.HumanoidRootPart.Position.Z)
		script.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position,lookAtPos)
		if curWaypoint > 0 then
			print(curWaypoint) --This is the print which shows which waypoint it's currently moving to
		end
	end
end