Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.14 KB | None | 0 0
  1. local tool = script.Parent.Parent
  2. local player = game:GetService("Players").LocalPlayer
  3. local mouse = player:GetMouse()
  4. local hole = tool:WaitForChild("Hole")
  5. local handle = tool:WaitForChild("Handle")
  6. local UIS = game:GetService("UserInputService")
  7. local RS = game:GetService("RunService");
  8. local TS = game:GetService("TweenService")
  9. local mouseDown = false
  10. local equipped = false
  11. local reloading = false
  12. local oldIcon = mouse.Icon
  13. local sprinting = false
  14. local relDeb = false
  15. local flash = hole.FlashGui
  16. local lastShot = tick()
  17.  
  18. local animations = tool:WaitForChild("Animations")
  19. local configs = tool:WaitForChild("Configs")
  20. local remotes = tool:WaitForChild("Remotes")
  21.  
  22. local holdAnim = animations:WaitForChild("Hold")
  23. local sprintAnim = animations:WaitForChild("Sprint")
  24. local reloadAnim = animations:WaitForChild("Reload")
  25.  
  26. local holdTrack
  27. local sprintTrack
  28. local reloadTrack
  29.  
  30. local allowTracing = configs:WaitForChild("AllowTracing")
  31. local range = configs:WaitForChild("Range")
  32.  
  33. local configs = tool:WaitForChild("Configs")
  34. local remotes = tool:WaitForChild("Remotes")
  35.  
  36. local ammo = configs:WaitForChild("Ammo")
  37. local reserveAmmo = configs:WaitForChild("ReserveAmmo")
  38. local magSize = configs:WaitForChild("MagSize")
  39. local damage = configs:WaitForChild("Damage")
  40. local fireRate = configs:WaitForChild("FireRate")
  41. local range = configs:WaitForChild("Range")
  42. local reloadTime = configs:WaitForChild("ReloadTime")
  43.  
  44. local canShootRemote = remotes:WaitForChild("CanShoot")
  45. local canReloadRemote = remotes:WaitForChild("CanReload")
  46. local reloadRemote = remotes:WaitForChild("Reload")
  47. local hitRemote = remotes:WaitForChild("Hit")
  48. local shootRemote = remotes:WaitForChild("Shoot")
  49. local traceRemote = remotes:WaitForChild("Trace")
  50. local andagain = remotes:WaitForChild("andbackagain")
  51.  
  52. local emptySound = handle:WaitForChild("EmptySound")
  53. local reloadSound = handle:WaitForChild("ReloadSound")
  54. local shootSound = handle:WaitForChild("ShootSound")
  55.  
  56. local function equip()
  57.     equipped = true
  58.    
  59.     local oldIcon = mouse.Icon
  60.     mouse.Icon = "rbxassetid://4247417907"
  61.    
  62.     local character = player.Character or player.CharacterAdded:Wait()
  63.     local humanoid = character:WaitForChild("Humanoid")
  64.    
  65.     if humanoid then
  66.         pcall(function()
  67.             holdTrack = humanoid:LoadAnimation(holdAnim)
  68.             holdTrack:Play()
  69.         end)
  70.         pcall(function()
  71.             sprintTrack = humanoid:LoadAnimation(sprintAnim)
  72.         end)
  73.     end
  74. end
  75.  
  76. local function canReload(plr)
  77.     if ammo.Value < magSize.Value then
  78.         if reserveAmmo.Value > 0 then
  79.             if not reloading then
  80.                 if equipped then
  81.                     return true
  82.                 end
  83.             end
  84.         end
  85.     end
  86.    
  87.     return false
  88. end
  89.  
  90. local function sprint(actionName, inputState, inputObj)
  91.     if equipped == false then return false end
  92.    
  93.     local character = player.Character or player.CharacterAdded:Wait()
  94.     local humanoid = character:WaitForChild("Humanoid")
  95.    
  96.     sprintTrack:Play()
  97.     holdTrack:Stop()
  98.     humanoid.WalkSpeed = 30
  99.     sprinting = true
  100. end
  101.  
  102. local function stopSprinting()
  103.     if equipped == false then return false end
  104.    
  105.     local character = player.Character or player.CharacterAdded:Wait()
  106.     local humanoid = character:WaitForChild("Humanoid")
  107.    
  108.     sprintTrack:Stop()
  109.     holdTrack:Play()
  110.     humanoid.WalkSpeed = 16
  111.     sprinting = false
  112. end
  113.  
  114. local function canShoot(plr, playSound)
  115.     local character = player.Character or player.CharacterAdded:Wait()
  116.     local humanoid = character:WaitForChild("Humanoid")
  117.    
  118.     if math.abs(lastShot - tick()) > (60/fireRate.Value) then
  119.         if not reloading then
  120.             if equipped then
  121.                 if ammo.Value > 0 then
  122.                     if sprinting == false then
  123.                         if humanoid.Health > 0 then
  124.                             return true
  125.                         else
  126.                             if playSound then emptySound.Playing = true end
  127.                         end
  128.                     end
  129.                 end
  130.             end
  131.         end
  132.     end
  133.  
  134.     return false
  135. end
  136.  
  137. local function unequip()
  138.     wait(.1)
  139.     equipped = false
  140.     local character = player.Character or player.CharacterAdded:Wait()
  141.     local humanoid = character:WaitForChild("Humanoid")
  142.    
  143.     sprinting = false
  144.     humanoid.WalkSpeed = 16
  145.    
  146.     mouse.Icon = oldIcon
  147.    
  148.     if holdTrack then
  149.         holdTrack:Stop()
  150.     end
  151.     if sprintTrack then
  152.         sprintTrack:Stop()
  153.     end
  154. end
  155.  
  156. local function reload(plr)
  157.     if not canReload() then return end
  158.    
  159.     reloading = true
  160.     reloadSound:Play()
  161.    
  162.     ammo.Value = "REL"
  163.    
  164.     if reserveAmmo.Value < 0 then
  165.         ammo.Value = ammo.Value + reserveAmmo.Value
  166.         reserveAmmo.Value = 0
  167.     end
  168.    
  169.     wait(reloadTime.Value + .1)
  170.     local needed = magSize.Value - ammo.Value
  171.     reserveAmmo.Value = reserveAmmo.Value - needed
  172.     ammo.Value = magSize.Value
  173.     reloading = false
  174. end
  175.  
  176. local function shoot()
  177.     local character = player.Character or player.CharacterAdded:Wait()
  178.     local humanoid = character:WaitForChild("Humanoid")
  179.    
  180.     if humanoid.Health >= 0 then
  181.         if not canShoot(player, true) then return end
  182.        
  183.         lastShot = tick()
  184.         ammo.Value = ammo.Value - 1
  185.     end
  186. end
  187.  
  188. local function fire()
  189.     if wait() then
  190.         if not canShoot(player, false) then return end
  191.        
  192.         local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p).unit * range.Value)
  193.         local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true)
  194.        
  195.         if touch then
  196.             hitRemote:FireServer(touch)
  197.         end
  198.         shoot()
  199.         traceRemote:FireServer(position)
  200.         local character = player.Character or player.CharacterAdded:Wait()
  201.         local humanoid = character:WaitForChild("Humanoid")
  202.        
  203.         local Origin = hole.CFrame.p
  204.         local trace1 = Instance.new("Part")
  205.         trace1.CanCollide = false
  206.         trace1.BrickColor = BrickColor.new("Cyan")
  207.         trace1.Material = Enum.Material.Neon
  208.         trace1.CFrame = CFrame.new(hole.CFrame.p, position)
  209.            
  210.         local distance1 = (hole.CFrame.p - position).magnitude
  211.         local speed = 125
  212.         local TIME = (hole.CFrame.p - mouse.Hit.p).Magnitude / speed
  213.         local tweenI = TweenInfo.new(TIME, Enum.EasingStyle.Linear)
  214.         local tweenT = {Position = mouse.Hit.p}
  215.         local tweenC = TS:Create(trace1, tweenI, tweenT)
  216.         trace1.Size = Vector3.new(.2, .2, 2.5)
  217.         trace1.Parent = workspace
  218.         tweenC:Play()
  219.  
  220.         tweenC.Completed:Connect(function()
  221.             trace1:Destroy()
  222.         end)
  223.         game:GetService("Debris"):AddItem(trace1,30)
  224.     end
  225. end
  226.  
  227. mouse.Move:Connect(function()
  228.     if not equipped then return end
  229.     if mouse.Target then
  230.         if game.Players:GetPlayerFromCharacter(mouse.Target.Parent) then
  231.             mouse.Icon = "rbxassetid://4248522206"
  232.         elseif game.Players:GetPlayerFromCharacter(mouse.Target.Parent.Parent) then
  233.             mouse.Icon = "rbxassetid://4248522206"
  234.         else
  235.             mouse.Icon = "rbxassetid://4247417907"
  236.         end
  237.     end
  238. end)
  239.  
  240. tool.Equipped:Connect(function()
  241.     equip()
  242.  
  243.     mouse.Button1Up:Connect(function()
  244.         mouseDown = false
  245.     end)
  246.    
  247.     tool.Activated:Connect(function()
  248.         mouseDown = true
  249.         repeat
  250.             fire()
  251.         until not mouseDown
  252.     end)
  253. end)
  254.  
  255. tool.Unequipped:Connect(unequip)
  256.  
  257. wait(.1)
  258.  
  259. UIS.InputBegan:Connect(function(inp)
  260.     local keyCode = inp.KeyCode
  261.    
  262.     if keyCode == Enum.KeyCode.R then
  263.         reload()
  264.     end
  265.    
  266.     if keyCode == Enum.KeyCode.LeftShift then
  267.         sprint()
  268.     end
  269. end)
  270.  
  271. UIS.InputEnded:Connect(function(inp)
  272.     local keyCode = inp.KeyCode
  273.    
  274.     if keyCode == Enum.KeyCode.LeftShift then
  275.         stopSprinting()
  276.     end
  277. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement