Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.22 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 actionService = game:GetService("ContextActionService")
  7. local mouseDown = false
  8. local equipped = false
  9. local oldIcon = mouse.Icon
  10. local sprinting = false
  11. local relDeb = false
  12.  
  13. local animations = tool:WaitForChild("Animations")
  14. local configs = tool:WaitForChild("Configs")
  15. local remotes = tool:WaitForChild("Remotes")
  16.  
  17. local holdAnim = animations:WaitForChild("Hold")
  18. local sprintAnim = animations:WaitForChild("Sprint")
  19. local reloadAnim = animations:WaitForChild("Reload")
  20.  
  21. local holdTrack
  22. local sprintTrack
  23. local reloadTrack
  24.  
  25. local allowTracing = configs:WaitForChild("AllowTracing")
  26. local range = configs:WaitForChild("Range")
  27.  
  28. local canShoot = remotes:WaitForChild("CanShoot")
  29. local canReload = remotes:WaitForChild("CanReload")
  30. local hitRemote = remotes:WaitForChild("Hit")
  31. local reloadRemote = remotes:WaitForChild("Reload")
  32. local shootRemote = remotes:WaitForChild("Shoot")
  33.  
  34. local function equip()
  35.     equipped = true
  36.    
  37.     local oldIcon = mouse.Icon
  38.     mouse.Icon = "rbxassetid://4132185302"
  39.  
  40.     local character = player.Character or player.CharacterAdded:Wait()
  41.     local humanoid = character:WaitForChild("Humanoid")
  42.    
  43.     if humanoid then
  44.         pcall(function()
  45.             holdTrack = humanoid:LoadAnimation(holdAnim)
  46.             holdTrack:Play()
  47.         end)
  48.         pcall(function()
  49.             sprintTrack = humanoid:LoadAnimation(sprintAnim)
  50.         end)
  51.         pcall(function()
  52.             reloadTrack = humanoid:LoadAnimation(reloadAnim)
  53.         end)
  54.     end
  55. end
  56.  
  57. local function unequip()
  58.     equipped = false
  59.     local character = player.Character or player.CharacterAdded:Wait()
  60.     local humanoid = character:WaitForChild("Humanoid")
  61.    
  62.     sprinting = false
  63.     humanoid.WalkSpeed = 16
  64.    
  65.     mouse.Icon = oldIcon
  66.  
  67.     if holdTrack then
  68.         holdTrack:Stop()
  69.     end
  70.     if sprintTrack then
  71.         sprintTrack:Stop()
  72.     end
  73. end
  74.  
  75. local function reload()
  76.     reloadRemote:FireServer()
  77.     wait()
  78.     if canReload and relDeb == false and script.Parent.Parent.Configs.Reload.Value == true then
  79.         relDeb = true
  80.        
  81.         reloadTrack:Play()
  82.         wait(.01)
  83.         reloadRemote:FireServer()
  84.        
  85.         wait(2)
  86.         relDeb = false
  87.     end
  88. end
  89.  
  90. local function sprint(actionName, inputState, inputObj)
  91.    
  92.     local character = player.Character or player.CharacterAdded:Wait()
  93.     local humanoid = character:WaitForChild("Humanoid")
  94.    
  95.     if inputState == Enum.UserInputState.Begin then
  96.         if sprinting == false then
  97.             sprintTrack:Play()
  98.             holdTrack:Stop()
  99.             humanoid.WalkSpeed = 30
  100.             sprinting = true
  101.         else
  102.             sprintTrack:Stop()
  103.             holdTrack:Play()
  104.             humanoid.WalkSpeed = 16
  105.             sprinting = false
  106.         end
  107.     end
  108. end
  109.  
  110. local function fire()
  111.     if canShoot then
  112.         wait()
  113.         local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p).unit * range.Value)
  114.         local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true)
  115.        
  116.         if touch then
  117.             hitRemote:FireServer()
  118.         end
  119.         shootRemote:FireServer()
  120.        
  121.         local character = player.Character or player.CharacterAdded:Wait()
  122.         local humanoid = character:WaitForChild("Humanoid")
  123.        
  124.         if sprintTrack then
  125.             sprintTrack:Stop()
  126.             holdTrack:Play()
  127.             humanoid.WalkSpeed = 16
  128.         end
  129.        
  130.         if allowTracing.Value and script.Parent.Parent.Configs.Trace.Value == true then
  131.             local trace = Instance.new("Part")
  132.             trace.Anchored = trace
  133.             trace.CanCollide = false
  134.             trace.Transparency = 0.5
  135.             trace.BrickColor = BrickColor.new("Cool yellow")
  136.             trace.Material = Enum.Material.Neon
  137.            
  138.             local distance = (hole.CFrame.p - position).magnitude
  139.             trace.Size = Vector3.new(.1, .1, distance)
  140.             trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
  141.             trace.Parent = workspace
  142.            
  143.             game:GetService("Debris"):AddItem(trace, 0.025)
  144.         end
  145.     end
  146. end
  147.  
  148. tool.Equipped:Connect(function()
  149.     equip()
  150.  
  151.     mouse.Button1Up:Connect(function()
  152.         mouseDown = false
  153.     end)
  154.    
  155.     tool.Activated:Connect(function()
  156.         mouseDown = true
  157.         repeat
  158.             fire()
  159.         until not mouseDown
  160.     end)
  161. end)
  162.  
  163. tool.Unequipped:Connect(unequip)
  164. actionService:BindAction("Reload", reload, false, Enum.KeyCode.R)
  165. actionService:BindAction("Sprint", sprint, false, Enum.KeyCode.E)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement