Advertisement
Guest User

Untitled

a guest
Apr 9th, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local mouse = player:GetMouse()
  3. local gun = script.Parent
  4. local isShooting = false
  5. local cooldownTime = 0.5 -- Cooldown for shooting, same as the server script
  6. local lastShotTime = 0
  7.  
  8. -- This function fires a shot to the server
  9. local function fireShot()
  10. local mp = mouse.Hit.Position
  11. script.Parent.shot:FireServer(mp)
  12. end
  13.  
  14. -- Detect if mouse button is held down
  15. mouse.Button1Down:Connect(function()
  16. isShooting = true
  17. end)
  18.  
  19. mouse.Button1Up:Connect(function()
  20. isShooting = false
  21. end)
  22.  
  23. game:GetService("RunService").Heartbeat:Connect(function()
  24. local currentTime = tick()
  25.  
  26. if isShooting then
  27. -- Only fire if enough time has passed based on the cooldown
  28. if currentTime - lastShotTime >= cooldownTime then
  29. fireShot()
  30. lastShotTime = currentTime -- Update the time of the last shot fired
  31. end
  32. end
  33. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement