Enemy Keeps flipping on X axis

I’m trying to have the enemy follow the player and flipping the sprite to keep the enemy facing the player. However, when the player is on top of the enemy, they’re neither on the left nor right of the enemy so the enemy starts flipping erratically. Here’s my code trying to fix the issue, but it doesn’t work:

private void ChasePlayer()
    {   
        // left side of player
        if (transform.position.x < player.position.x)
        {
            rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
            transform.localScale = Vector3.one;
            isFacingLeft = false;
        }
        else if (transform.position.x > player.position.x) //right side of player
        {
            rb.velocity = new Vector2(-moveSpeed, rb.velocity.y);
            transform.localScale = new Vector3(-1f, 1f, 1f);
            isFacingLeft = true;
        } else
        {
            transform.localScale = Vector3.one;
        }
    }

Any help would be appreciated, thank you in advance.

You can limit their response frequency.

private float startTime = 0;
private void ChasePlayerWithLimitedFrequency()
{
    if (Time.time - startTime < 1f) // 1 second limit
        return;

    startTime = Time.time;

    // left side of player
    if (transform.position.x < player.position.x)
    {
        rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
        transform.localScale = Vector3.one;
        isFacingLeft = false;
    }
    else if (transform.position.x > player.position.x) //right side of player
    {
        rb.velocity = new Vector2(-moveSpeed, rb.velocity.y);
        transform.localScale = new Vector3(-1f, 1f, 1f);
        isFacingLeft = true;
    } 
    else
    {
        transform.localScale = Vector3.one;
    }
}