Character won't Idle in correct direction (won't transition to corrrect animation)

Hi, I’m new to unity and just wanted to ask if this is a problem with my script. This part of the code is used for making the player do the correct idle animation, but it just goes back to the front facing idle animation and I do not understand why.

if (movement.x == 1|| movement.x == -1 || movement.y == 1 || movement.y == -1) ;
        {
            animator.SetFloat("lastMoveX", movement.x);
            animator.SetFloat("lastMoveY", movement.y);
        }

Full Code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 5f;
    public Rigidbody2D rd;
    Vector2 movement;
    public Animator animator;
    public SpriteRenderer sr;


    public void Awake()
    {
        sr = GetComponent<SpriteRenderer>();
    }

    void Update()
    {
        //input
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
        movement = movement.normalized;


        animator.SetFloat("Horizontal", movement.x);
        animator.SetFloat("Vertical", movement.y);
        animator.SetFloat("speed", movement.sqrMagnitude);





        if (Input.GetKey("left"))
        {
            
            if (sr != null)
            {
                // flip the sprite
                sr.flipX = true;
            }

        }

            if (Input.GetKey("right"))
            {
                // flip the sprite
                sr.flipX = false;
            }


        if (movement.x == 1|| movement.x == -1 || movement.y == 1 || movement.y == -1) ;
        {
            animator.SetFloat("lastMoveX", movement.x);
            animator.SetFloat("lastMoveY", movement.y);
        }



    }

    void FixedUpdate()
    {
        //movement
        rd.MovePosition(rd.position + movement * moveSpeed * Time.fixedDeltaTime);

    }


}

6146468--671270--IdlePic.PNG

The problem might be that you’re normalizing the movement vector (line 24), but I think you really want to be rounding your x and y components. Check and make sure your x,y components are 0 when they’re supposed to be 0.

Yes, I’ve fixed this and this was exactly the problem, thanks for replying!