parent player to object when you press a button a set amount of time

Is there a way to do this? So far I have a parenting code but it doesn't seem to last long enough for me to know if it works or not.

var prefab: Transform;
var Parent : GameObject;
var Map3 : Transform;

function Update () {
    if (Input.GetKeyDown("z")){
        transform.parent = Map3.gameObject.transform;
        }
    else
        transform.parent= null;
    if (Input.GetKeyDown("z")){
        transform.parent = Map3.gameObject.transform;
        }
    else
        transform.parent= null;
    if (Input.GetKeyDown("z")){
        transform.parent = Map3.gameObject.transform;
        }
    else
        transform.parent= null;
    if (Input.GetKeyDown("z")){
        transform.parent = Map3.gameObject.transform;
        }
    else
        transform.parent= null;
}

try using Input.GetKey(). this will continue to return true as long as you hold down the key. Also instead of setting the parent to null every frame you could keep track of how long it has been since you set the parent and only set it to null after a couple of seconds.