Advertisement
Prexxo

Gun Handler Tool - Client

Mar 21st, 2024
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local UIS = game:GetService("UserInputService")
  4. local RunService = game:GetService("RunService")
  5. local Workspace = game:GetService("Workspace")
  6.  
  7. local Modules = require(ReplicatedStorage:WaitForChild("Modules"))
  8. local Network = Modules.Get("Network")
  9. local InputUtility = Modules.Get("Input")
  10. local Utility = Modules.Get("Utility")
  11. local ObjectManager = Modules.Get("ObjectManager")
  12. local BulletManager = Modules.Get("BulletManager")
  13.  
  14. local LocalPlayer = Players.LocalPlayer
  15. local Mouse = LocalPlayer:GetMouse()
  16. local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
  17. local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
  18. local RootPart = Character:WaitForChild("HumanoidRootPart")
  19. local Humanoid = Character:WaitForChild("Humanoid")
  20.  
  21. local GunGui = PlayerGui:WaitForChild("Gun")
  22. local CooldownFrame = GunGui:WaitForChild("Cooldown")
  23. local CooldownBar = CooldownFrame:WaitForChild("Bar")
  24.  
  25. local Tool = script.Parent
  26.  
  27. local ReloadTime = 1/80
  28. local LastFired = 0
  29.  
  30. local function CanFire()
  31.     return Character.Parent and Humanoid.Health > 0 and os.clock()-LastFired > ReloadTime
  32. end
  33.  
  34. Tool.Activated:Connect(function()
  35.     if not CanFire() then return end
  36.     LastFired = os.clock()
  37.    
  38.     CooldownFrame.Visible = true
  39.     CooldownBar.Size = UDim2.fromScale(1, 1)
  40.    
  41.     CooldownBar:TweenSize(UDim2.fromScale(0, 1), Enum.EasingDirection.In, Enum.EasingStyle.Linear, ReloadTime, true, function(DidComplete)
  42.         if not DidComplete then return end
  43.        
  44.         CooldownFrame.Visible = false
  45.     end)
  46.    
  47.    
  48.     while UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) do
  49.         local BulletOrigin = RootPart.Position
  50.         local BulletDirection = Mouse.Hit.LookVector
  51.         Network.FireTo("Server", "FireGun", BulletOrigin, BulletDirection)
  52.         BulletManager.CreateBullet(BulletOrigin, BulletDirection)
  53.        
  54.         task.wait(ReloadTime)
  55.     end
  56. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement