Hello!
I've been trying to figure out a way to stop bullet spam and Ive been using this method listed below.
Mouse.Button1Down:connect(function(Mouse) Firing = true if Active == true and Ammo.Value >= 0 and GunReady == true then GunReady = false Dead() CreateBullet() wait(FireRate/60) end if Active == true and Ammo.Value <= 0 then Firing = false Empty:Play() end GunReady = true wait(1) end) Mouse.Button1Up:connect(function(Mouse) Firing = false end)
Any help would be greatly appreciated. Cheers.
Well, after reading your script quickly I noticed a few errors that'd cause your problems.
First, I'm gonna cover your problem in the comments, where you said it's able to fire when your ammo is at 0. That's because of line 3, where you used Ammo.Value >= 0
. Instead, it should be either Ammo.Value > 0
. or Ammo.Value >= 1
. Now, as for the second part, the fix should be kinda simple. Try moving the wait(FireRate/60)
to line 17, then add GunReady = true
below it, kinda like this:
Mouse.Button1Down:connect(function(Mouse) Firing = true if Active == true and Ammo.Value >= 0 and GunReady == true then GunReady = false Dead() CreateBullet() end if Active == true and Ammo.Value <= 0 then Firing = false Empty:Play() end GunReady = true wait(1) end) wait(FireRate/60) GunReady = true Mouse.Button1Up:connect(function(Mouse) Firing = false end)
If it doesn't work, let me know, as there are a few things I'm not sure of.
First off, line 1 has 2 errors: connect is deprecated, switch to Connect. 2nd error is you passed a parameter of "mouse" when the Button1Down event has no parameters, PLUS you already HAVE the mouse defined. And yeah the ammo stuff was already answered.