Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local mouse = player:GetMouse()
- local gun = script.Parent
- local isShooting = false
- local cooldownTime = 0.5 -- Cooldown for shooting, same as the server script
- local lastShotTime = 0
- -- This function fires a shot to the server
- local function fireShot()
- local mp = mouse.Hit.Position
- script.Parent.shot:FireServer(mp)
- end
- -- Detect if mouse button is held down
- mouse.Button1Down:Connect(function()
- isShooting = true
- end)
- mouse.Button1Up:Connect(function()
- isShooting = false
- end)
- game:GetService("RunService").Heartbeat:Connect(function()
- local currentTime = tick()
- if isShooting then
- -- Only fire if enough time has passed based on the cooldown
- if currentTime - lastShotTime >= cooldownTime then
- fireShot()
- lastShotTime = currentTime -- Update the time of the last shot fired
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement