gameobject X Rotation Reset Help

I have a script that causes the scripted gameobject to rotate along the x axis towards the right when I hold down the left mouse button and then rotates backwards to it’s original rotation of 0 when I let go. However when I parent this gameobject to a first person character controller and move around while I’m holding down the mouse button the gameobject either keeps rotating forever or just stays in it’s current rotation when I let go. Am I checking for the right value with if (transform.rotation.x > 0)? I’ve tried checking with the parent’s X rotation instead like this (transform.parent.rotation.x > 0) but it nothing changed.

using UnityEngine;
using System.Collections;

public class GameobjectXRotationReset : MonoBehaviour {
    // Use this for initialization
    void Start () {
    }
   
    // Update is called once per frame
    void Update () {
        if (Input.GetMouseButton(0)){
        transform.Rotate(Vector3.right * 10);
        }
        if (!Input.GetMouseButton(0)){
            if (transform.rotation.x > 0){
                transform.Rotate(Vector3.left);
            }
        }
    }
}

use transform.lcoalRotation instead of transform.rotation .