Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.29 KB | None | 0 0
  1. local hitmeplz = {"Arm1","Arm2","Chest","Face","Leg1","Leg2"}
  2. local player
  3. local tool = script.Parent.Parent
  4. local handle = tool:WaitForChild("Handle")
  5. local hole = tool:WaitForChild("Hole")
  6. local flash = hole.FlashGui
  7. local lastShot = tick()
  8. local equipped = false
  9. local reloading = false
  10.  
  11. local configs = tool:WaitForChild("Configs")
  12. local remotes = tool:WaitForChild("Remotes")
  13.  
  14. local ammo = configs:WaitForChild("Ammo")
  15. local reserveAmmo = configs:WaitForChild("ReserveAmmo")
  16. local magSize = configs:WaitForChild("MagSize")
  17. local damage = configs:WaitForChild("Damage")
  18. local fireRate = configs:WaitForChild("FireRate")
  19. local headMultiplier = configs:WaitForChild("HeadMultiplier")
  20. local range = configs:WaitForChild("Range")
  21. local reloadTime = configs:WaitForChild("ReloadTime")
  22.  
  23. local canShootRemote = remotes:WaitForChild("CanShoot")
  24. local canReloadRemote = remotes:WaitForChild("CanReload")
  25. local reloadRemote = remotes:WaitForChild("Reload")
  26. local hitRemote = remotes:WaitForChild("Hit")
  27. local shootRemote = remotes:WaitForChild("Shoot")
  28.  
  29. local emptySound = handle:WaitForChild("EmptySound")
  30. local reloadSound = handle:WaitForChild("ReloadSound")
  31. local shootSound = handle:WaitForChild("ShootSound")
  32. local headshotSound = handle:WaitForChild("HeadshotSound")
  33.  
  34. local function canReload(plr)
  35.     if ammo.Value < magSize.Value then
  36.         if reserveAmmo.Value > 0 then
  37.             if not reloading then
  38.                 if equipped then
  39.                     return true
  40.                 end
  41.             end
  42.         end
  43.     end
  44.    
  45.     return false
  46. end
  47.  
  48. local function reload(plr)
  49.     if not canReload() then return end
  50.    
  51.     reloading = true
  52.     script.Parent.Parent.Configs.Reload.Value = true
  53.     reloadSound:Play()
  54.    
  55.     ammo.Value = "REL"
  56.    
  57.     if reserveAmmo.Value < 0 then
  58.         ammo.Value = ammo.Value + reserveAmmo.Value
  59.         reserveAmmo.Value = 0
  60.     end
  61.    
  62.     wait(reloadTime.Value + .1)
  63.     local needed = magSize.Value - ammo.Value
  64.     reserveAmmo.Value = reserveAmmo.Value - needed
  65.     ammo.Value = magSize.Value
  66.     reloading = false
  67.     script.Parent.Parent.Configs.Reload.Value = false
  68. end
  69.  
  70. local function canShoot(plr, playSound)
  71.     if math.abs(lastShot - tick()) > (60/fireRate.Value) then
  72.         if not reloading then
  73.             if equipped then
  74.                 if ammo.Value > 0 then
  75.                     return true
  76.                 else
  77.                     if playSound then
  78.                         emptySound:Play()
  79.                     end
  80.                 end
  81.             end
  82.         end
  83.     end
  84.  
  85.     return false
  86. end
  87.  
  88. local function shoot()
  89.     local character = player.Character or player.CharacterAdded:Wait()
  90.     local humanoid = character:WaitForChild("Humanoid")
  91.    
  92.     if humanoid.Health >= 0 then
  93.         if not canShoot(player, true) then return end
  94.        
  95.         shootSound:Play()
  96.         lastShot = tick()
  97.         ammo.Value = ammo.Value - 1
  98.        
  99.         flash.Enabled = true
  100.         script.Parent.Parent.Configs.Trace.Value = true
  101.         wait(60/fireRate.Value)
  102.         flash.Enabled = false
  103.         script.Parent.Parent.Configs.Trace.Value = false
  104.     end
  105. end
  106.  
  107. local function hit(plr, part)
  108.     if not canShoot() then return end
  109.     if not part then return end
  110.  
  111.     local character = player.Character or player.CharacterAdded:Wait()
  112.     local rootPart = character:WaitForChild("HumanoidRootPart")
  113.    
  114.     if rootPart then
  115.         if (rootPart.CFrame.p - part.CFrame.p).magnitude <= range.Value then --//Check range
  116.             local humanoid
  117.  
  118.             if part.Name == "Handle" then
  119.                 humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
  120.             else
  121.                 humanoid = part.Parent:FindFirstChild("Humanoid")
  122.             end
  123.            
  124.             for i,v in pairs(hitmeplz) do
  125.                 if part.Parent.Name == v then
  126.                     humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
  127.                 end
  128.             end
  129.            
  130.             if humanoid and humanoid.Health > 0 then --//Do nothing if humanoid is dead
  131.                 local newDamage = damage.Value
  132.  
  133.                 if part.Name == "Head" then
  134.                     newDamage = newDamage * headMultiplier.Value
  135.  
  136.                     local soundCopy = headshotSound:Clone()
  137.                     soundCopy.Parent = part
  138.                     soundCopy:Play()
  139.                 end
  140.  
  141.                 humanoid:TakeDamage(newDamage)
  142.             end
  143.         end
  144.     end
  145. end
  146.  
  147. local function equip()
  148.     equipped = true
  149.     player = game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
  150. end
  151.  
  152. local function dequip()
  153.     equipped = false
  154. end
  155.  
  156. tool.Equipped:Connect(equip)
  157. tool.Unequipped:Connect(dequip)
  158. hitRemote.OnServerEvent:Connect(hit)
  159. shootRemote.OnServerEvent:Connect(shoot)
  160. reloadRemote.OnServerEvent:Connect(reload)
  161. canShootRemote.OnServerInvoke = canShoot
  162. canReloadRemote.OnServerInvoke = canReload
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement