AI Lookat script Only using the z axis

How can I make an AI lookat script with only the z axis rotating?

var target;

function Start()
{
target = GameObject.CompareTag("Player"); // this might be wrong cuz I wrote it on my phone
}

function Update()
{
//Look at
}

Vector3 toTargetVector = target.position - transform.position;
float zRotation = Mathf.Atan2( toTargetVector.y, toTargetVector.x )*Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(new Vector3 ( 0, 0, zRotation);

This points the X axis at the target… if you want to point the Y axis at the target replace the second line with …

float zRotation = ( Mathf.Atan2( toTargetVector.y, toTargetVector.x )*Mathf.Rad2Deg ) -90.0f;

Maybe something like:

Vector3 target;

void Update(){

 transform.LookAt(target);    
 transform.rotation.eulerAngles = new Vector3(0,0, transform.rotation.eulerAngles.z);    
}