Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to prevent Bullet Spam?

Asked by 6 years ago

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.

0
Another problem Im having is, it also is able to fire when Ammo.Value == 0 Decimaprism 65 — 6y

2 answers

Log in to vote
0
Answered by
ax_gold 360 Moderation Voter
6 years ago

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.

0
Ya, thats a negative. It crashes the game when wait(fireRate/60) is moved down to line 16 Decimaprism 65 — 6y
0
oops sorry. Try moving the wait and gunready to line 15 instead (before the "end)") ax_gold 360 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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.

0
Same for the Button1Uo event. User#19524 175 — 6y

Answer this question