Hide,show ability

How to make a object to hide after pressing a button and auto show after some seconds?

function Update() {

    if (Input.GetKeyDown(KeyCode.Z)) {
       // hide
        renderer.enabled = false;
 yield WaitForSeconds(Random.Range(1,8));
        renderer.enabled = true;
    }

   
}

the code above dont work

Im pretty sure you cant have yeild waitforseconds in the update, without an if statement. as the update is constantly being called so your asking your code to waitforseconds everytime the update() loops through.

you could do something like this, as it would only happen once

var name : boolean = false;

function update(){

if (Input.GetKeyDown("z") && name == false) {
        name = true;
        renderer.enabled = false;
        yield WaitForSeconds(Random.Range(1,8)); // im assuming this code is correct btw
        name = false;
        renderer.enabled = true;
}
}

thx for answer but now i get this error for
name = true;
and
name = false;

**skills\hide.js(16,16): Error BCE0022: Cannot convert 'boolean' to 'String'. (BCE0022) (Assembly-UnityScript)**