Need Help With a Walk/Sprint Animation

I’m trying to create a script with the animations that make the player’s head bob however with the code I currently have it only plays one animation for one side instead of two when you sprint. Help?

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

public class headbob : MonoBehaviour
{
    public CharacterController playerController;
    public Animation anim; //Empty GameObject's animation component
    private bool isMoving;
    private bool shiftpressed;


    private bool left;
    private bool right;

    void CameraAnimations()
    {
        if (playerController.isGrounded == true)
        {
            if (isMoving == true)
            {
                if (left == true)
                {
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        if (!anim.isPlaying)
                        {
                            anim.Play("sprintLeft");
                            left = false;
                            right = true;
                        }
                    }
                    else if (!anim.isPlaying)
                    {
                        anim.Play("walkLeft");
                        left = false;
                        right = true;
                    }

                }

                if(right == true)
                {
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        if (anim.isPlaying)
                        {
                            anim.Play("sprintRight");
                            right = false;
                            left = true;
                        }
                    }
                    else if (!anim.isPlaying)
                    {
                        anim.Play("walkRight");
                        right = false;
                        left = true;
                    }
                }
               
            }
        }
    }


    void Start()
    { //First step in a new scene/life/etc. will be "walkLeft"
        left = false;
        right = true;

   
    }


    void Update()
    {
        float inputX = Input.GetAxis("Horizontal"); //Keyboard input to determine if player is moving
        float inputY = Input.GetAxis("Vertical");

      


        if (inputX != 0 || inputY != 0)
        {
            isMoving = true;
        }
        else if (inputX == 0 && inputY == 0)
        {
            isMoving = false;
        }

        CameraAnimations();

    }
}

[ICODE][/ICODE]

Line 46: if (anim.isPlaying)
Should be: if (!anim.isPlaying)

Thank you, I guess I’m blind then huh.