Advertisement
HowToRoblox

CannonHandler

Jan 6th, 2021
2,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local shootPoint = script.Parent:WaitForChild("ShootPoint")
  2. local trigger = script.Parent:WaitForChild("Trigger")
  3.  
  4.  
  5. local ball = game.ServerStorage:WaitForChild("CannonBall")
  6.  
  7.  
  8. local cooldown = 3
  9. local isCooldown = false
  10.  
  11.  
  12.  
  13. trigger:WaitForChild("ClickDetector").MouseClick:Connect(function()
  14.    
  15.    
  16.     if isCooldown then return end
  17.     isCooldown = true
  18.    
  19.    
  20.     local ballClone = ball:Clone()
  21.    
  22.     ballClone.CFrame = shootPoint.CFrame
  23.    
  24.     local bv = Instance.new("BodyVelocity")
  25.     bv.Velocity = shootPoint.CFrame.LookVector * 500
  26.     bv.Parent = ballClone
  27.    
  28.     ballClone.Parent = workspace
  29.    
  30.    
  31.     shootPoint:WaitForChild("GunSound"):Play()
  32.    
  33.    
  34.     local hitCharacters = {}
  35.    
  36.     ballClone.Touched:Connect(function(touched)
  37.        
  38.         if touched.Parent ~= script.Parent and touched.Parent.Parent ~= script.Parent then
  39.            
  40.            
  41.             local humanoid = touched.Parent:FindFirstChild("Humanoid") or touched.Parent.Parent:FindFirstChild("Humanoid")
  42.            
  43.             if humanoid and not hitCharacters[humanoid.Parent] then
  44.                
  45.                 hitCharacters[humanoid.Parent] = true
  46.                
  47.                
  48.                 humanoid:TakeDamage(80)
  49.             end
  50.            
  51.             ballClone:Destroy()
  52.         end
  53.     end)
  54.    
  55.    
  56.     wait(0.1)
  57.     bv:Destroy()
  58.    
  59.    
  60.     wait(cooldown - 0.1)
  61.     isCooldown = false
  62.     hitCharacters = {}
  63. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement