Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. local function pathfind()
  2. local target = findnearbyplayers()
  3. if not target then
  4. local path = pathfinding:CreatePath()
  5. local rand = humanoidrp.Position + Vector3.new(math.random(-50,50),0,math.random(-50,50))
  6. path:ComputeAsync(humanoidrp.Position,rand)
  7.  
  8. local waypoints = path:GetWaypoints()
  9. for i,v in pairs(waypoints) do
  10. if Enum.PathWaypointAction.Jump == v.Action then
  11. humanoid.Jump = true
  12. end
  13. print('no')
  14. humanoid:MoveTo(v.Position)
  15.  
  16. local movefinished = humanoid.MoveToFinished:Wait()
  17. if not movefinished then
  18. getunstuck()
  19. break
  20. end
  21. end
  22. else
  23. local path = pathfinding:CreatePath()
  24. path:ComputeAsync(humanoidrp.Position,target.Position)
  25. local waypoints = path:GetWaypoints()
  26.  
  27. for i,v in pairs(waypoints) do
  28. if Enum.PathWaypointAction.Jump == v.Action then
  29. humanoid.Jump = true
  30. end
  31. humanoid:MoveTo(v.Position)
  32.  
  33. local wrap = coroutine.wrap(function()
  34. if humanoid.WalkToPoint.Y > humanoidrp.Position.Y then
  35. humanoid.Jump = true
  36. end
  37. end)
  38.  
  39. wrap()
  40.  
  41. local movefinished = humanoid.MoveToFinished:Wait()
  42. if not movefinished then
  43. getunstuck()
  44. break
  45. end
  46. if checksight(target) and (torso.Position - target.Position).Magnitude < 20 then
  47. break
  48. end
  49. if i % 5 == 0 then
  50. if findnearbyplayers() ~= target then
  51. break
  52. end
  53. end
  54. if (target.Position-waypoints[#waypoints].Position).Magnitude > 8 then
  55. break
  56. end
  57. end
  58. end
  59. end
  60.  
  61.  
  62. local function main()
  63. local target = findnearbyplayers()
  64. if target then
  65. if not checksight(target) or (target.Position - torso.Position).Magnitude > 30 then
  66. pathfind()
  67. end
  68. end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement