Rotate a objects Z axis (only) back to 0 slowly

Problem:

Hi all, I want to Rotate a objects Z axis back to 0 slowly but I only want to rotate it’s Z axis and It has to be slow so that if the player is moving on the Z axis with the controls for movement it won’t be obstructed by this script adjusting the Z axis.
Question:

Here is a script a friend gave me, but I don’t know how to do just the Z axis could someone point me in the right direction?
Script:

var target: Transform;
var speed: float = 25.0;
 
function Update () {    
    var step = speed * Time.deltaTime;
 
    var v3 = target.right - (Vector3.Dot(target.right, transform.forward) * transform.forward);
    var q = Quaternion.FromToRotation(transform.right, v3);
    transform.rotation = Quaternion.RotateTowards(transform.rotation, q, step);
}

Answer: (by @Vunpac)

so the final code should look like this

var speed: float = 1;
function Update ()
{
var wantedrotation = Vector3(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 1);
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(wantedrotation), Time.time * speed);
}

and once attached to the desired object it Rotates the objects Z axis back to 0

Replace your code in update with this, and it should do what you want.

var wantedRotation = Vector3(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 0)
transform.rotation = Quaternion.Slerp(transform.rotation, wantedRotation, Time.deltaTime * speed)

when dealing with the values in majority of the functions in Unity3D you will need float variables. and if you are putting a raw value in then you will usually have to add a suffix f to the end. Like

10f

so change speed back to a float or change the 10 to 10f.

also my mistake I also forgot wanted position needs to be a quaternion so lets change the code to:

var wantedrotation = Vector3(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 1); 
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(wantedrotation), Time.time * speed);