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

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

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

✓ Accepted answer

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.

2 comments

0

Techically, you defined fire as a boolean. :P

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?

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.

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