While(true) script help!

Hi, here is my script,

  function () {
        
        while(true) {
        
        
        if (Input.GetKey ("s")){
        
            audio.volume = 0.0;
         
         
        yield WaitForSeconds(3);
         
        
           audio.volume = 1.0;
        
        }
        }
        }

It’s supposed to mute the volume for three seconds after the S key is pushed. I wrote it myself and put it into Unity as a Java script, but something seems to be wrong with it. Maybe one of your more skilled minds can figure out the problem. I’ve tried but nothing seems to work. Thanks for reading!

-Rov

Did not test this code, but I would do this. You can’t check for input inside a function until the function is fired so I would look in Update for the input:

function Update()
{
	 if (Input.GetKeyDown ("s"))
		MuteForThreeSeconds ();
}

function MuteForThreeSeconds () 
{
    audio.volume = 0.0;

	yield WaitForSeconds(3);

	audio.volume = 1.0;
}

There is no need for the while loop.