How to fix enemy's rotation (2D)

So I have a script assigned to my enemy for it to follow my player and the problem is it keeps rotating on the y axis, How can i fix this, Here’s the script:

public Transform Player;
 int  MoveSpeed = 4;
 float MaxDist = 10f;
 float MinDist = 5f;
 
  void Update ()
  {
      transform.LookAt(Player);
      if (Vector2.Distance(transform.position, Player.position) >= MinDist)
      {
          transform.position += transform.forward * MoveSpeed * Time.deltaTime;
          if (Vector2.Distance(transform.position, Player.position) <= MaxDist)
          {
              //Here Call a function for shooting
          }
      }
  }

If it has a rigidbody you can just add a constraint so that it cannot rotate in y. The transform should still override this so the script should still work.