Advertisement
HowToRoblox

GunScript

Nov 23rd, 2019
4,362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. local Gun = script.Parent
  2. local Gunshot = Gun:WaitForChild("Gunshot")
  3. local OnHit = script.Parent.OnHit
  4. local debounce = false
  5. local Ammo = 5
  6. local ReloadingSound = Gun:WaitForChild("Reloading")
  7. local Reloading = false
  8. local UIS = game:GetService("UserInputService")
  9. local Player = game:GetService("Players").LocalPlayer
  10. local Headshot = false
  11.  
  12. Player.PlayerGui.GunInfo.InfoFrame.Visible = false
  13.  
  14. Gun.Equipped:Connect(function(Mouse)
  15.     Player.PlayerGui.GunInfo.InfoFrame.GunName.Text = Gun.Name
  16.     Player.PlayerGui.GunInfo.InfoFrame.KillsText.Text = ("Kills: " .. script.Kills.Value)
  17.     Player.PlayerGui.GunInfo.InfoFrame.AmmoText.Text = ("Ammo: " .. Ammo .. "/5")
  18.     Player.PlayerGui.GunInfo.InfoFrame.Visible = true
  19.     Mouse.Icon = "rbxassetid://4450645985"
  20.     Gun.Activated:Connect(function()       
  21.         if debounce == false and Reloading == false then
  22.             if Ammo > 0 then
  23.                 debounce = true
  24.                
  25.                 Ammo = Ammo - 1
  26.                 Ammo = Ammo
  27.                 Player.PlayerGui.GunInfo.InfoFrame.AmmoText.Text = ("Ammo: " .. Ammo .. "/5")
  28.                    
  29.                 Gunshot:Play()
  30.                
  31.                 for i,x in pairs(Gun:WaitForChild("Flare"):GetChildren())do
  32.                     if x.ClassName == "Decal" then
  33.                         x.Transparency = 0
  34.                     end
  35.                 end
  36.                 wait(0.03)
  37.                 for i,x in pairs(Gun:WaitForChild("Flare"):GetChildren())do
  38.                     if x.ClassName == "Decal" then
  39.                         x.Transparency = 1
  40.                     end
  41.                 end
  42.                    
  43.                 if Mouse.Target then
  44.                     if Mouse.Target.Parent:FindFirstChild("Humanoid") then
  45.                         if Mouse.Target.Name == "Head" then
  46.                             Headshot = true
  47.                         end
  48.                         OnHit:FireServer(Mouse.Target.Parent, Headshot)
  49.                         wait(0.1)
  50.                         Headshot = false
  51.                         Player.PlayerGui.GunInfo.InfoFrame.KillsText.Text = ("Kills: " .. script.Kills.Value)
  52.                     end
  53.                 end
  54.        
  55.                 wait(0.7)
  56.                 debounce = false
  57.                
  58.             elseif Reloading == false then
  59.                 Mouse.Icon = "rbxassetid://4450665798"
  60.                 Reloading = true   
  61.                 ReloadingSound:Play()
  62.                 Player.PlayerGui.GunInfo.InfoFrame.AmmoText.Text = ("Reloading..")
  63.                 wait(3)
  64.                 Ammo = 5
  65.                 script:FindFirstChild("Ammo").Value = Ammo
  66.                 Player.PlayerGui.GunInfo.InfoFrame.AmmoText.Text = ("Ammo: " .. Ammo .. "/5")
  67.                 Reloading = false
  68.                 Mouse.Icon = "rbxassetid://4450645985"
  69.             end
  70.         end
  71.     end)
  72.    
  73.     UIS.InputBegan:Connect(function(Key)
  74.         if Key.KeyCode == Enum.KeyCode.R and Reloading == false and Ammo ~= 5 then
  75.             Mouse.Icon = "rbxassetid://4450665798"
  76.             Reloading = true   
  77.             ReloadingSound:Play()
  78.             Player.PlayerGui.GunInfo.InfoFrame.AmmoText.Text = ("Reloading..")
  79.             wait(3)
  80.             Ammo = 5
  81.             script:FindFirstChild("Ammo").Value = Ammo
  82.             Player.PlayerGui.GunInfo.InfoFrame.AmmoText.Text = ("Ammo: " .. Ammo .. "/5")
  83.             Reloading = false
  84.             Mouse.Icon = "rbxassetid://4450645985"
  85.         end
  86.     end)
  87. end)
  88.  
  89. Gun.Unequipped:Connect(function()
  90.     Player.PlayerGui.GunInfo.InfoFrame.Visible = false
  91. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement