local p=game:GetService("PathfindingService")
local target = script.Parent.Target.Value.Torso
local v = script.Parent
local parts = script.Parent:GetChildren()
local path=p:ComputeRawPathAsync(v.Torso.Position,target.Position,500)
if(v.Torso.Position-target.Position).magnitude<4 and target~=v.Torso then
target:Destroy()
end
local points=path:GetPointCoordinates()
if #points>1 then
for i=1,10 do
local part,point=workspace:FindPartOnRay(Ray.new(points[math.min(#points,i)],Vector3.new(0,-10,0)))
local part,point2=workspace:FindPartOnRay(Ray.new(points[math.min(#points,i+1)],Vector3.new(0,-10,0)))
local count=0
while math.min((point2-v.Torso.Position).magnitude,(point*Vector3.new(1,0,1)-v.Torso.Position*Vector3.new(1,0,1)).magnitude)>3 and count<50 do
count=count+1
v.Humanoid:MoveTo(point2)
if workspace:FindPartOnRay(Ray.new(v.Torso.Position,CFrame.new(v.Torso.Position*Vector3.new(1,0,1),point2*Vector3.new(1,0,1)).lookVector*4))then
v.Humanoid:MoveTo(point)
end
if workspace:FindPartOnRay(Ray.new(v.Torso.Position,CFrame.new(v.Torso.Position*Vector3.new(1,0,1),point*Vector3.new(1,0,1)).lookVector*3))then
v.Humanoid.Jump=true
end
wait()
end
end
else
v.Humanoid:MoveTo(target.Position)
if target.Position.Y>=v.Humanoid.Torso.Position.Y+1 then
v.Humanoid.Jump=true
end
end
this is a pathfinding script. i want this to make the the NPC that has this script in him to follow the target. but it doesnt follow him. it moves to 1 place then stops there. it doesnt follow the player right. please can you help me with this.
