Guest User

Updated Sound Script

a guest
May 25th, 2017
2,482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.73 KB | None | 0 0
  1. --//Make sure you've added the sounds to the Handle and named them correctly!
  2. --//Variables
  3. local plr = game.Players.LocalPlayer
  4. local tool = script.Parent.Parent
  5. local hole = tool.Hole
  6. local handle = tool.Handle
  7. local debounce = true
  8. local config = tool.Config
  9. local range = config.Range
  10. local dmg = config.Damage
  11. local coolDown = config.CoolDown
  12. local clips = config.Clips
  13. local ammo = config.Ammo
  14. local maxAmmo = config.MaxAmmo
  15. local allowTracing = config.AllowTracing
  16. local reloadTime = config.ReloadTime
  17. local isReloading = false
  18. --//Sounds
  19. local reloadSound = tool.Handle.ReloadSound
  20. local fireSound = tool.Handle.FireSound
  21. local equipSound = tool.Handle.EquipSound
  22. local emptySound = tool.Handle.EmptySound
  23.  
  24. --//Events
  25. tool.Equipped:connect(function(mouse)
  26.     equipSound:Play()
  27.     tool.Activated:connect(function()
  28.         if not isReloading then
  29.             if ammo.Value > 0 then
  30.                 if debounce then
  31.                     --//Play sound
  32.                     fireSound:Play()
  33.                     --//Doesn't allow spamming
  34.                     debounce = false
  35.                     --//Ray Get, Set
  36.                     local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p) * range.Value)
  37.                     local hit, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
  38.                    
  39.                     --//Bullet Tracing
  40.                     if allowTracing.Value == true then
  41.                         --//Make part
  42.                         local trace = Instance.new("Part", workspace)
  43.                         trace.Material = Enum.Material.Neon
  44.                         trace.BrickColor = BrickColor.new("Black")
  45.                         trace.CanCollide = false
  46.                         trace.Anchored = true
  47.                         trace.Transparency = 0.5
  48.                        
  49.                         --//Show Direction
  50.                         local distance = (hole.CFrame.p - position).magnitude
  51.                         trace.Size = Vector3.new(0.2, 0.2, distance)
  52.                         trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
  53.                        
  54.                         --//Remove debris
  55.                         game:GetService("Debris"):AddItem(trace, 0.1)
  56.                     end
  57.                    
  58.                     --//Hit Detection
  59.                     if hit then
  60.                         local humanoid =  hit.Parent:FindFirstChild("Humanoid")
  61.                         if humanoid then
  62.                             if hit.Name == "Head" then
  63.                                 --//Double damage on headshots
  64.                                 humanoid:TakeDamage(dmg.Value*2)
  65.                             else
  66.                                 --//Normal Damage on body shots
  67.                                 humanoid:TakeDamage(dmg.Value)
  68.                             end
  69.                         end
  70.                     end
  71.                     ammo.Value = ammo.Value - 1
  72.                     wait(coolDown.Value)
  73.                     debounce = true
  74.                 end
  75.             else
  76.                 --//Out of ammo
  77.                 emptySound:Play()
  78.             end
  79.         end
  80.     end)
  81.    
  82.     --//Reload Event
  83.     mouse.KeyDown:connect(function(key)
  84.         key:lower()
  85.         if key == "r" then
  86.             if not isReloading then
  87.                 if clips.Value > 0 then
  88.                     reloadSound:Play()
  89.                     isReloading = true
  90.                     ammo.Value = maxAmmo.Value
  91.                     clips.Value = clips.Value - 1
  92.                     wait(reloadTime.Value)
  93.                     isReloading = false
  94.                 end
  95.             end
  96.         end
  97.     end)
  98. end)
Advertisement
Add Comment
Please, Sign In to add comment