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

Does anyone know how to make this wok for Automatic Fire instead of Single Shot?

Asked by 9 years ago
if (key == "f") then
        if (not isFiring) and (not cloakActive.Value) and (not shieldActive.Value) and (speed.Value < fireSpeed) then
            isFiring = true

            fire()
            wait(weaponsCooldown)

            isFiring = false
        end
    end

Need it to make a Viper weapons system from Battlestar Galactica

2 answers

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

I'm not entirely sure what system you have set up, but it's pretty easy to do. Just use a while loop to make yourself keep firing.

local fire = false

mouse.Button1Down:connect(function()
    fire = true
end)

mouse.Button1Up:connect(function()
    fire = false
end)

while fire do
    wait(0.1)
    fire()
end

Of course this assumes that you have mouse and fire() defined somewhere.

0
Techically, you defined `fire` as a boolean. :P adark 5487 — 9y
0
'fire' is defined as a boolean, but this assumes that 'fire()' is defined somewhere as a function. One would not override the other, would it? Perci1 4988 — 9y
Ad
Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

To use your own code, OP, you're going to have to connect both the KeyDown and KeyUp events:

if (key == "f") then --[[in KeyDown]]
        if (not isFiring) and (not cloakActive.Value) and (not shieldActive.Value) and (speed.Value < fireSpeed) then
            isFiring = true

        while isFiring do
             fire()
              wait(weaponsCooldown)
        end
        end
    end

if (key == "f") then --[[in KeyUp]]
        if (not isFiring) and (not cloakActive.Value) and (not shieldActive.Value) and (speed.Value < fireSpeed) then
            isFiring = false
        end
    end

This requires isFiring to be defined outside of either event, however, so that the same variable is accessible to both.

Answer this question