How would I go about making a ranged NPC via pathfindingservice?

I am trying to make a ranged NPC. What I am trying to accomplish is to have an enemy NPC that goes near the player but stays a few studs away. I thought I found a method on how to do it but for some reason pathfinding service returns it’s status as nopath whenever I attempt to. As soon as I edit the script to just moving all the way to the character it suddenly works. I don’t know why this happens. Does anyone have any insight why/ a better method on how to do it with pathfindingservice?

--Script for ranged NPC computing
pathtotarget:ComputeAsync(npc.HumanoidRootPart.Position,CFrame.new(npc.HumanoidRootPart.Position, target.HumanoidRootPart.Position).LookVector*50)```

Make sure the NPC has a clear path to the end point. Also you should make sure you’re CFrame.new is not nil.

The CFrame isn’t nil. The NPC should have a clear path. No errors are outputting, I just don’t understand whats happening. whenever I check it’s status it gives nopath.