HowToRoblox

GunClient

May 23rd, 2020
2,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. local plr = game.Players.LocalPlayer
  2. local mouse = plr:GetMouse()
  3.  
  4. local uis = game:GetService("UserInputService")
  5.  
  6. local onBulletShot = script.Parent:WaitForChild("OnBulletShot")
  7. local onReload = script.Parent:WaitForChild("OnReload")
  8. local onCursorChange = script.Parent:WaitForChild("OnCursorChange")
  9.  
  10. local isDown = false
  11.  
  12. local timePerBullet = 0.2
  13. local isCooldown = false
  14.  
  15.  
  16. uis.InputBegan:Connect(function(input, processed)
  17.  
  18.     if script.Parent.Parent == plr.Character then
  19.    
  20.         if input.KeyCode ~= Enum.KeyCode.R or processed then return end
  21.        
  22.         onReload:FireServer()
  23.     end
  24. end)
  25.  
  26. onCursorChange.OnClientEvent:Connect(function(mouseIcon)
  27.            
  28.     mouse.Icon = mouseIcon
  29. end)
  30.  
  31.  
  32. mouse.Button1Down:Connect(function()
  33.    
  34.     isDown = true
  35. end)
  36.  
  37. mouse.Button1Up:Connect(function()
  38.    
  39.     isDown = false
  40. end)
  41.  
  42.  
  43. while wait() do
  44.    
  45.     if script.Parent.Parent == plr.Character and not isCooldown then
  46.    
  47.         if isDown then
  48.            
  49.             isCooldown = true
  50.            
  51.             onBulletShot:FireServer(mouse.Hit, mouse.Target)
  52.            
  53.             wait(timePerBullet)
  54.            
  55.             isCooldown = false
  56.         end
  57.     end
  58. end
Add Comment
Please, Sign In to add comment