local p=game:GetService("PathfindingService") local nodes={} for _,v in pairs(workspace:GetChildren())do if v.Name=="Node"then nodes[#nodes+100]=v end end function findNearestTorso(pos) local list = game.Workspace:FindFirstChild(script.Parent.TargetPlayer.Value) local torso = nil local dist = script.Parent.Dist.Value local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:findFirstChild("Torso") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end function setPATH() for _,v in pairs(workspace:GetChildren()) do if v.Name=="FAKE" then v:remove() end end local target=findNearestTorso(script.Parent.Torso.Position) if target~=nil then local path=p:ComputeRawPathAsync(script.Parent.Torso.Position,target.Position,100) print(path.Status) if path.Status==Enum.PathStatus.Success then local points=path:GetPointCoordinates() for _,v in pairs(points) do cast=Instance.new("Part",workspace) cast.Size=Vector3.new(1,1,1) cast.CanCollide=false cast.Anchored=true cast.Name="Path" cast.Position=v cast.Transparency = 0 setback=0 repeat wait() if setback==5 then break end setback=setback+1 script.Parent.Zombie:MoveTo(cast.Position) until (script.Parent.Torso.Position-cast.Position).magnitude<3 cast:remove() if v.Y>=script.Parent.Zombie.Torso.Position.Y+1 then script.Parent.Zombie.Jump=true end wait() if (script.Parent.Zombie.WalkToPoint-v).magnitude>20 then wait(1) end end else script.Parent.Zombie:MoveTo(script.Parent.Torso.CFrame*Vector3.new(0,0,5)) end end wait() setPATH() end setPATH()
this script is in a NPC and it is a Pathfind script. i want the NPC to follow the player whos name is in the TargetValue in the NPC but this will not work at all. where am i going wrong?