Advertisement
HowToRoblox

GrenadeHandler

Feb 14th, 2021
2,991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. local tool = script.Parent
  2.  
  3.  
  4. local cooldown = 3
  5. local coolingDown = false
  6.  
  7. local explodesIn = 3
  8.  
  9.  
  10. local char
  11.  
  12.  
  13. tool.Equipped:Connect(function()
  14.    
  15.     char = tool.Parent
  16. end)
  17.  
  18. tool.Unequipped:Connect(function()
  19.    
  20.     char = nil
  21. end)
  22.  
  23.  
  24. local mouseCF
  25.  
  26. tool.MouseInfoRE.OnServerEvent:Connect(function(plr, mouseHit)
  27.    
  28.     mouseCF = mouseHit
  29. end)
  30.  
  31.  
  32. tool.Activated:Connect(function()
  33.    
  34.     if coolingDown then return end
  35.    
  36.     coolingDown = true
  37.    
  38.    
  39.     char.Humanoid:LoadAnimation(script.ThrowAnim):Play()
  40.    
  41.     wait(0.1)
  42.    
  43.    
  44.     local clone = tool.Handle:Clone()
  45.    
  46.     tool.Handle.Transparency = 1
  47.    
  48.    
  49.     local bv = Instance.new("BodyVelocity")
  50.     bv.Velocity = mouseCF.LookVector * 100
  51.     bv.Parent = clone
  52.    
  53.    
  54.     clone.Parent = workspace
  55.    
  56.     clone.CanCollide = true
  57.    
  58.    
  59.     local explodeCoro = coroutine.wrap(function()
  60.        
  61.        
  62.         wait(explodesIn)
  63.        
  64.         local explosion = Instance.new("Explosion")
  65.        
  66.         explosion.Position = clone.Position
  67.        
  68.         explosion.Parent = clone
  69.        
  70.         clone.ExplodeSound:Play()
  71.        
  72.         wait(1)
  73.         clone:Destroy()
  74.     end)
  75.    
  76.     explodeCoro()
  77.    
  78.    
  79.     wait(0.1)
  80.    
  81.     bv:Destroy()
  82.    
  83.  
  84.     wait(cooldown - 0.2)
  85.    
  86.     tool.Handle.Transparency = 0
  87.     coolingDown = false
  88. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement