Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. wait(.7)
  2. --variables
  3. local pathfinding = game:GetService("PathfindingService")
  4. local debris = game:GetService("Debris")
  5. local tweenservice = game:GetService("TweenService")
  6.  
  7. local mob = script.Parent
  8. local humanoid = mob:WaitForChild('Humanoid')
  9. local humanoidrp = mob:WaitForChild('HumanoidRootPart')
  10. local torso = mob:WaitForChild('Torso')
  11.  
  12. local attack1 = true
  13. local attack2 = true
  14. local attack3 = true
  15.  
  16. local function findnearbyplayers()
  17. local dist = 5000
  18. local plr = nil
  19. for i,v in pairs(game.Workspace:GetChildren()) do
  20. if v:FindFirstChild('Humanoid') and v.Name ~= 'Dummy' then
  21. local hum = v:FindFirstChild('Humanoid')
  22. local humroot = v:FindFirstChild('HumanoidRootPart')
  23. local mag = (humanoidrp.Position-humroot.Position).Magnitude
  24. if mag < dist and hum.Health > 0 then
  25. mag = dist
  26. plr = humroot
  27. end
  28. end
  29. end
  30. return plr,dist
  31. end
  32.  
  33. local function getunstuck()
  34. local pos = humanoidrp.Position + Vector3.new(math.random(-30,30),0,math.random(-30,30))
  35. humanoid:MoveTo(pos)
  36. humanoid.Jump = true
  37. end
  38.  
  39. local function checksight(target)
  40. local ray = Ray.new(humanoidrp.Position,(target.Position-humanoidrp.Position).Unit*20)
  41. local hit,position = game.Workspace:FindPartOnRayWithIgnoreList(ray,{script.Parent})
  42. if hit then
  43. if hit:IsDescendantOf(target.Parent) then
  44. return true
  45. end
  46. end
  47. return false
  48. end
  49.  
  50. local function pathfind()
  51. local target = findnearbyplayers()
  52. if not target then
  53. local path = pathfinding:CreatePath()
  54. local rand = humanoidrp.Position + Vector3.new(math.random(-50,50),0,math.random(-50,50))
  55. path:ComputeAsync(humanoidrp.Position,rand)
  56.  
  57. local waypoints = path:GetWaypoints()
  58. for i,v in pairs(waypoints) do
  59. if Enum.PathWaypointAction.Jump == v.Action then
  60. humanoid.Jump = true
  61. end
  62. print('no')
  63. humanoid:MoveTo(v.Position)
  64.  
  65. local movefinished = humanoid.MoveToFinished:Wait()
  66. if not movefinished then
  67. getunstuck()
  68. break
  69. end
  70. end
  71. else
  72. local path = pathfinding:CreatePath()
  73. path:ComputeAsync(humanoidrp.Position,target.Position)
  74. local waypoints = path:GetWaypoints()
  75.  
  76. for i,v in pairs(waypoints) do
  77. if Enum.PathWaypointAction.Jump == v.Action then
  78. humanoid.Jump = true
  79. end
  80. print('yes')
  81. humanoid:MoveTo(v.Position)
  82.  
  83. spawn(function()
  84. if humanoid.WalkToPoint.Y > humanoidrp.Position.Y then
  85. humanoid.Jump = true
  86. end
  87. end)
  88. local movefinished = humanoid.MoveToFinished:Wait()
  89. if not movefinished then
  90. getunstuck()
  91. break
  92. end
  93. if checksight(target) and math.abs(math.abs(humanoidrp.Position.Y) - math.abs(target.Position.Y)) < 3 then
  94. break
  95. end
  96. if i % 5 == 0 then
  97. if findnearbyplayers() ~= target then
  98. break
  99. end
  100. end
  101. end
  102. end
  103. end
  104.  
  105.  
  106. local function main()
  107. local target = findnearbyplayers()
  108. if target then
  109. print('B')
  110. if checksight(target) and math.abs(math.abs(humanoidrp.Position.Y) - math.abs(target.Position.Y)) < 3 then
  111. pathfind()
  112. else
  113. pathfind()
  114. end
  115. end
  116. end
  117.  
  118. while true do
  119. if humanoid.Health < 1 then
  120. break
  121. end
  122.  
  123. main()
  124.  
  125. wait()
  126. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement