Animator SetBool not changing to true C#

I’m quite positive I have done everything correctly however the Animator still doesn’t want to set the parameters to true so the transition can take effect. If you would like me to post a photo of the animator I will however I assure you the parameters are setup correctly with the transitions and all spelled correctly.

Here I assign the hash and bool values.
public KeyCode Forward;
public KeyCode Backward;
public KeyCode Left;
public KeyCode Right;

public Animator PlayerAnimations;
public bool IsMoving;
public int moveHash;
public int attackHash;
public bool CanAttack;

void Start()
{
    Forward = KeyCode.W
    Backward = KeyCode.S
    Left = KeyCode.A
    Right = KeyCode.D
    
    PlayerAnimations = GetComponent<Animator>();

    moveHash = Animator.StringToHash("IsMoving");
    attackHash = Animator.StringToHash("IsAttacking");
    IsMoving = true;
    CanAttack = true;
}

Then here I tell it if one of the 4 movement keys are hit switch the parameter for the moving transition to true, and likewise for the attack if the left mouse button is clicked

    void Update()
    {
        //If one of the 4 movement keys are hit transition into moving animation or if not go back to idle
        if (Input.GetKey(Forward))
            
        {
            transform.Translate(Vector3.forward * 5 * Time.deltaTime);
            IsMoving = true;
            PlayerAnimations.SetBool(moveHash, IsMoving);
        }
        if(Input.GetKey(Backward))
        {
            transform.Translate(Vector3.back * 5 * Time.deltaTime);
            IsMoving = true;
            PlayerAnimations.SetBool(moveHash, IsMoving);
        }
        if(Input.GetKey(Left))
    
        {
            transform.Rotate(-Vector3.up * 30 * Time.deltaTime);
            IsMoving = true;
            PlayerAnimations.SetBool(moveHash, IsMoving);
        }
            
        if(Input.GetKey(Right))
        {
            transform.Rotate(Vector3.up * 30 * Time.deltaTime);
            IsMoving = true;
            PlayerAnimations.SetBool(moveHash, IsMoving);
        }
        else
        {
            IsMoving = false;
            PlayerAnimations.SetBool(moveHash, IsMoving);
        }
    
        //If the left mouse button is clicked transition into attack animation
        if(Input.GetMouseButtonDown(0))
        {
            PlayerAnimations.SetBool(attackHash, CanAttack);
        }
        else
        {
            CanAttack = false;
        }
    }

I didn’t test if this solves you problem but you are using ‘if/else’ in the wrong way. With else in line 31 you are setting IsMoving = false every time you are not pressing the ‘Right’-key.

Change your code to something like:

    void Update()
     {
         IsMoving = false;
         //If one of the 4 movement keys are hit transition into moving animation or if not go back to idle
         if (Input.GetKey(Forward))                 
         {
             transform.Translate(Vector3.forward * 5 * Time.deltaTime);
             IsMoving = true;
         }
         if(Input.GetKey(Backward))
         {
             transform.Translate(Vector3.back * 5 * Time.deltaTime);
             IsMoving = true;
         }
         if(Input.GetKey(Left))
     
         {
             transform.Rotate(-Vector3.up * 30 * Time.deltaTime);
             IsMoving = true;
         }
             
         if(Input.GetKey(Right))
         {
             transform.Rotate(Vector3.up * 30 * Time.deltaTime);
             IsMoving = true;
         }
         PlayerAnimations.SetBool(moveHash, IsMoving);
        //If the left mouse button is clicked transition into attack animation
         if(Input.GetMouseButtonDown(0))
         {
             PlayerAnimations.SetBool(attackHash, CanAttack);
         }
         else
         {
             CanAttack = false;
         }
     }