EnemyNPC's, Pathfinding, and other questions

Hello! So, i have a few questions about a smart NPC system that i am creating. First of all the way the system works is it loops through a hostile npc storage folder in the replicated storage, finds an npc, then loops through a hostile npc spawn folder in the workspace, which has a number value in it with its spawn cap (how many will spawn at this location), which then loops through an npc function that creates the npcs and runs all their code. I want to preface with saying that this has been wonderful for me so far, and works great.

My questions involve first the pathfinding service which i’m attempting to use because i like that the npc can navigate around walls and objects and all that. First of all… how do you stop a pathfind? Because i’d like the pathfind to change more often because new object appear and the destination changes as the Player moves. Second, in this code… how could i hault the npc when he gets to a certain point? I dont want the npc trying to hug the Player or anything… i want them to close but not right on top… but close enough for the npcs attack to register, or if its a magic using npc… for it to hault say 15 studs away from the player. I probably could solve this myself if i could find anywhere a way to stop the path find…

This is the small chunk of code.

        if not vaus then
			if dist <= settings.TargetEnemyDistance then
				--Raise the gui
				if target ~= nil and not TargetLocked then
					TargetLocked = true
					npc.Humanoid.WalkSpeed = 16
					
					local path = 
                    PathfindingService:FindPathAsync(npc.UpperTorso.Position, target.Position)
					local points = path:GetWaypoints()
					
					if path.Status == Enum.PathStatus.Success then
						for i,v in pairs(points) do
							npc.Humanoid:MoveTo(v.Position)
							npc.Humanoid.MoveToFinished:Wait()
							if v.Action == Enum.PathWaypointAction.Jump then
								npc.Humanoid.Jump = true
							end
						end
					end					
					attack(target)
					--npc.Humanoid:MoveTo(target.Position, target)
				end
				raus=true
			else
				if target == nil and  TargetLocked  then
					TargetLocked = false
					haus = false
					npc.Humanoid.WalkSpeed = 8
					
					local path = PathfindingService:FindPathAsync(npc.UpperTorso.Position, OriginalPosition)
					local points = path:GetWaypoints()
					
					if path.Status == Enum.PathStatus.Success then
						for i,v in pairs(points) do
							npc.Humanoid:MoveTo(v.Position)
							npc.Humanoid.MoveToFinished:Wait()
							if v.Action == Enum.PathWaypointAction.Jump then
								npc.Humanoid.Jump = true
							end
						end
					end
					
					--npc.Humanoid:MoveTo(OriginalPosition)
				end
				raus=false
			end
		end

Second, is pathfinding the way to go with this? And does anyone have any tips to make the npc a smarter? That last else goes back to his original position if the npc gets too far out of view of the player. And would it maybe be better if the npc has to view the player before exectuting the follow service? Thoughts on that?

Any help on ideas and thoughts on what i’ve talked about would be wonderful thx!