Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to prevent Bullet Spam?

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.

1 comment

0

Another problem Im having is, it also is able to fire when Ammo.Value == 0

2 answers

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.

2 comments

0

Ya, thats a negative. It crashes the game when wait(fireRate/60) is moved down to line 16

0

oops sorry. Try moving the wait and gunready to line 15 instead (before the "end)")

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.

1 comment

0

Same for the Button1Uo event.

This discussion is preserved as it was. New answers, comments, and votes are closed.