Muzzle flash help

I wrote a script telling a muzzle flash particle effect to spawn when someone clicks the left mouse button, it has the same variables as my raycasts which act as bullets this is so the muzzle flash can only play 8 times before having to reload.

This all worked fine for my pistol which shoots only once when the left mouse button has been clicked, but now I am trying to do the same thing for my machine gun which fires constantly until the mouse button has been let go of. I have tried changing my script but have had no luck, can someone help me out with this please?

This is my altered script (has no errors)

var muzzleFlash : GameObject;
var spawnPoint : Transform;
var fullClip : int = 30;
var bulletsLeft : int = 30;
var waitTime = 1.5;
var refireRate : float = 0.1;

function ShotPoller () {

while(true)
{
    if(Input.GetButton("Fire1"))
    {
        Shoot();
        
        yield WaitForSeconds(refireRate);
    }
    if(Input.GetKeyDown("r")){
        Reload();
    }

    yield;
}
}

function Start(){

StartCoroutine(ShotPoller());
}



if(Input.GetButtonDown("r")){
    Reload();
}


function Shoot () {

if(Input.GetButtonDown("Fire1")){
     if(bulletsLeft > 0 ){
            bulletsLeft -- ;

            Instantiate(muzzleFlash, spawnPoint.position, spawnPoint.rotation);
        }

}
}

function Reload () {

if(Input.GetButtonDown("r")){
yield WaitForSeconds(waitTime);
bulletsLeft = fullClip;

}
}

Just change your line -

if(Input.GetButtonDown("Fire1")){

to -

if(Input.GetButton("Fire1")){