I cannot get my rotation to reset properly

I have a first person controller and I’m working with a first person melee type game. When the player attacks and they are in range of an enemy The camera and player itself rotate towards the closest enemy using this script.

if (gosDistance < snapDistance)
{
    snapping.SetActive(true);
    var rotation = Quaternion.LookRotation(closest.transform.position - transform.position);
    //Debug.Log(rotation);
    player.transform.rotation.y = Quaternion.Slerp(transform.rotation.y, rotation.y, Time.deltaTime * damping);
    playerCamera.transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
    //playerController.transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}

The real problem I am having is afterwards the axes for the player and camera get stuck in a sort of gimbal lock I think and currently the only way I have for resetting that is to to change the player and cameras rotation all back to (0,0,0), but that doesn’t flow well with the gameplay. Is There any way that the camera and players rotation can be reset without having to face the player in a whole new direction? also here is my rotation reset code.

playerCamera.transform.rotation.y = 0;
playerCamera.transform.rotation.z = 0;

player.transform.rotation.y = 0;
player.transform.rotation.z = 0;

transform.rotation.x, transform.rotation.y, transform.rotation.z and transform.rotation.w are read-only. Any IDE worth its salt would’ve told you this.

If you wish to reset rotation, use:

transform.rotation = new Quaternion(x,y,z,w);
//or (note no "new")
transform.rotation.eulerAngles = Quaternion.Euler(x,y,z);
//or if you wish to only reset one axis...
transform.rotation.eulerAngles = Quaternion.Euler(transform.rotation.eulerAngles.x,y,transform.rotation.eulerAngles.z);

I’m having a similar issue where I can’t reset the rotation of the transform.

Code:

[SerializeField] private Transform currentRot;
[SerializeField] private Transform targetRot;
[SerializeField] private Transform resetRot;
[SerializeField] private float time;

public void Update()
{
    if(Input.GetKeyDown(KeyCode.E))
    {
        transform.rotation = Quaternion.Slerp(currentRot.rotation, targetRot.rotation, time);
        time = time + Time.deltaTime;
    }
    else if(Input.GetKeyUp(KeyCode.E))
    {
        transform.rotation = Quaternion.Slerp(resetRot.rotation, currentRot.rotation, time);
        time = time + Time.deltaTime;
    }
}