Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1.  
  2. local player = game:GetService('Players').LocalPlayer
  3. local mouse = player:GetMouse()
  4.  
  5. local range_min, range_max = 100, 100;
  6.  
  7. local playerData = player:FindFirstChild('System')
  8. local onTeam = playerData and playerData:FindFirstChild('OnTeam')
  9.  
  10. local storage = game:GetService('ReplicatedStorage')
  11. local gp = storage.gameplay
  12. local char = gp.character
  13. local val = char.value
  14.  
  15. local function find(t,i)
  16. for index, val in next, (t) do
  17. if (index == i) then
  18. return true, index, val
  19. elseif (val == i) then
  20. return true, index, val
  21. end
  22. end
  23. end
  24.  
  25. local hoops = (function()
  26. local hs = {},{};
  27.  
  28. local rec do
  29. rec = function(o)
  30. for __, child in next, (o:GetChildren()) do
  31. if string.lower(child['Name']):match('hoop') and child:FindFirstChild('Goal') then
  32. table.insert(hs, child)
  33. elseif #child:GetChildren() > 0 then
  34. rec(child)
  35. end
  36. end
  37. end
  38. end
  39.  
  40. rec(game.Workspace)
  41.  
  42. return hs
  43. end)()
  44.  
  45. local getShoot = function()
  46. local c = player.Character or player.CharacterAdded:wait()
  47. local hrp = c:WaitForChild('HumanoidRootPart',5)
  48. if not hrp then print('No humanoid root part.') return end
  49.  
  50.  
  51. local ball;
  52. for __, obj in next, (workspace:GetChildren()) do
  53. if obj.Name:lower() == 'basketball' and obj.controller.Value == player.Name then
  54. return obj.shoot
  55. end
  56. end
  57. end
  58.  
  59. local getHoop = function()
  60. local c = player.Character or player.CharacterAdded:wait()
  61. local hrp = c:WaitForChild('HumanoidRootPart',5)
  62. if not hrp then print('No humanoid root part.') return end
  63.  
  64. local last, closest = math.huge;
  65. for __, hoop in next, (hoops) do
  66. local goal = hoop:FindFirstChild('Goal')
  67.  
  68. if goal then
  69. local dist = (hrp.Position-goal.Position).magnitude
  70. if dist < last then
  71. last = dist
  72. closest = hoop
  73. end
  74. end
  75. end
  76. return closest
  77. end
  78.  
  79. local Attack = function(shoot, hoop)
  80. if shoot and hoop then
  81. val:FireServer("shooting", true)
  82. shoot:FireServer(hoop, math.random(range_min,range_max), true)
  83. end
  84. end
  85.  
  86. mouse.KeyDown:connect(function(key)
  87. if key == "q" then
  88. local shoot = getShoot()
  89. local hoop = getHoop()
  90.  
  91. court = hoop.Parent
  92. local data = court:FindFirstChild('GameData')
  93. local teamball = data and data:FindFirstChild('TeamBall')
  94.  
  95. local h1 = court:FindFirstChild('_Hoop1')
  96. local h2 = court:FindFirstChild('_Hoop2')
  97.  
  98. if OnTeam and OnTeam.Value == 1 and h1 then
  99. Attack(shoot,h1)
  100. return
  101. elseif OnTeam and OnTeam.Value == 2 and h2 then
  102. Attack(shoot,h2)
  103. return
  104. end
  105.  
  106. if teamball and teamball.Value == 1 and h1 then
  107. Attack(shoot,h1)
  108. return
  109. elseif teamball and teamball.Value == 2 and h2 then
  110. Attack(shoot,h2)
  111. return
  112. end
  113.  
  114.  
  115. Attack(shoot,hoop)
  116. end
  117. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement