Is there a way to stop a path with the pathfinding service? So for instance… i have an enemy npc, that will keep a certain amount of distance from the player because its a magic base npc, but there are many different kinds of npcs that all work off of this module code, so it has to be friendly with seperate values depending on the npc. That could just be done with:
Settings = {
EvilWizardHaltDistance = 15
}
So essentially my thought would be to break the path when the npc gets close enough to the player, with something like :Stop(), but ik thats not a function in the Pathfinding service, so maybe a vector distance subtraction between the players humanoid root part and npc?
Because its in a rendered step that needs to continue even if the path finding is ended. A while loop would really be expensive in a rendered step, wouldn’t it?
If you’re running the pathfollowing function on Hearbeat, then you can just add a conditional statement into your Heartbeat function to check if your Humanoid (or next waypoint) is within the halting radius
if (humanoidPos - targetPos) > 15 then
-- move forward
else
-- do nothing
end
You mentioned loops, but if you’re running on the Heartbeat event there is no need for loops, the heartbeat event essentially acts like a loop which fires every frame.