Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. bin = script.Parent
  2. debounce = 0
  3.  
  4. function move(target)
  5. local dir = (target.Position - bin.Position).unit
  6. local spawnPos = bin.Position
  7. local pos = spawnPos + (dir * 1)
  8. bin:findFirstChild("BodyGyro").cframe = CFrame.new(pos, pos + dir)
  9. bin:findFirstChild("BodyGyro").maxTorque = Vector3.new(9000,9000,9000)
  10. end
  11.  
  12. function moveTo(target)
  13. bin.Touched:Connect(function(hit)
  14. if hit.Parent:FindFirstChild('imhuman') and debounce == 0 then
  15. bin.BodyPosition.Position = bin.CFrame.LookVector * -10
  16. debounce = 1
  17. wait(1)
  18. debounce = 0
  19. print('worked')
  20. end
  21. end)
  22. bin.BodyPosition.position = target.Position
  23. bin.BodyPosition.maxForce = Vector3.new(10000,10000,10000) * bin.Speed.Value
  24. end
  25.  
  26. function findNearestTorso(pos)
  27. local list = game.Workspace:GetChildren()
  28. local torso = nil
  29. local dist = 1000
  30. local temp = nil
  31. local human = nil
  32. local temp2 = nil
  33. for x = 1, #list do
  34. temp2 = list[x]
  35. if (temp2.className == "Model") and (temp2 ~= script.Parent) then
  36. temp = temp2:findFirstChild("UpperTorso")
  37. human = temp2:findFirstChild("Humanoid")
  38. if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
  39. if (temp.Position - pos).magnitude < dist then
  40. torso = temp
  41. dist = (temp.Position - pos).magnitude
  42. end
  43. end
  44. end
  45. end
  46. return torso
  47. end
  48.  
  49. function shoot(pos)
  50. dir = (pos - bin.CFrame.p).unit
  51. for i = 1, 50 do
  52. local ex = Instance.new("Explosion")
  53. ex.BlastRadius = 1
  54. ex.Position = bin.Position + (dir * 10 * i) + (dir * 7)
  55. ex.Parent = game.Workspace
  56. end
  57. end
  58.  
  59. function shootAt(torso)
  60. local dir = (torso.Position - bin.Position).unit
  61. local spawnPos = bin.Position
  62. local pos = spawnPos + (dir * 1)
  63. shoot(pos)
  64. end
  65.  
  66. while true do
  67. local torso = findNearestTorso(bin.Position)
  68. if torso~=nil then
  69. move(torso)
  70. moveTo(torso)
  71. end
  72. wait()
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement