Unity Animator Prefab issue

So I am working on a code where the player presses a button and that will instantiate a prefab onto the scene.

Problem is the animation is not working on it. The conditions of the Animator are being met and switching to them but it’s stuck in the first animation it starts in (In this case, the walking animation) but when I drag the prefab out by hand, the animation plays just fine when the conditions are met.

What is up with my Unity code that is causing the instantiated prefab to not work while the prefab itself works fine when dragged in?

Code for the Ai

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

public class AllyController : MonoBehaviour
{
    public NavMeshAgent NAV;

    private Animator anim;

    public float BlockTimer = 3f;
    public float AttackRadius = 1.3f;
    public float AllyAttackTime = 2f;
    public float Speed = 5f;
    public float Health = 10f;
    public float AllySpotRange = 10f;

    bool EnemyAttackPointCheck, EnemySightCheck;
    bool HasAttacked = false;
    bool HasBlocked = false;

    public Transform EnemyObj;
    public Transform AllyEndPoint;

    public LayerMask EnemyFaction;
    public LayerMask Player;

    private void Awake()
    {
        NAV = GetComponent<NavMeshAgent>();
        anim = GetComponent<Animator>();
    }

    private void Update()
    {
        EnemySightCheck = Physics.CheckSphere(transform.position, AllySpotRange, EnemyFaction);
        EnemyAttackPointCheck = Physics.CheckSphere(transform.position, AttackRadius, EnemyFaction);

        if (!EnemyAttackPointCheck && !EnemySightCheck)
        {
            AllyMove();
        }

        if (!EnemyAttackPointCheck && EnemySightCheck)
        {
            AllySpotted();
        }

        if (EnemyAttackPointCheck && EnemySightCheck)
        {
            AllyAttack();
        }
    }

    void AllyMove()
    {
        anim.SetBool("IsWalking", true);
        anim.SetBool("IsMarching", false);
        anim.SetBool("IsAttacking", false);
        anim.SetBool("IsBlocking", false);

        NAV.SetDestination(AllyEndPoint.position);
    }

    void AllySpotted()
    {
        anim.SetBool("IsWalking", false);
        anim.SetBool("IsMarching", true);
        anim.SetBool("IsAttacking", false);
        anim.SetBool("IsBlocking", false);

        NAV.SetDestination(EnemyObj.position);

        Speed = 3f;
    }

    void AllyAttack()
    {
        NAV.SetDestination(transform.position);

        transform.LookAt(EnemyObj);

        if (!HasAttacked)
        {
            anim.SetBool("IsWalking", false);
            anim.SetBool("IsMarching", false);
            anim.SetBool("IsAttacking", true);
            anim.SetBool("IsBlocking", false);

            HasAttacked = true;

            Invoke(nameof(ResetAttackTimer), AllyAttackTime);
        }

        if (HasAttacked && !HasBlocked)
        {
            HasBlocked = true;

            anim.SetBool("IsWalking", false);
            anim.SetBool("IsMarching", false);
            anim.SetBool("IsAttacking", false);
            anim.SetBool("IsBlocking", true);

            Invoke(nameof(ResetBlockTimer), BlockTimer);
        }
    }

    void ResetAttackTimer()
    {
        anim.SetBool("IsAttacking", false);
        HasAttacked = false;
    }

    void ResetBlockTimer()
    {
        anim.SetBool("IsBlocking", false);
        HasBlocked = false;
    }

    void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(transform.position, AttackRadius);

        Gizmos.color = Color.green;
        Gizmos.DrawWireSphere(transform.position, AllySpotRange);
    }
}

The code that instantiates the prefab that is having the problem with the animation.

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

public class PlaySoldierSpawner : MonoBehaviour
{
    private Animator Anim;

    public int PlayerGold = 25;
    public int PlayerMaxTroops = 15;

    private int TroopCounter;

    private float GoldCountDownTimer = 10;
    private float ResetTimer = 10;

    public Transform AllyEndPoint;
    public Transform BaseSpawnPoint;
    public GameObject FootmanObj;

    public Text CounterTroop;
    public Text CounterGold;

    private void Awake()
    {
       Anim = GetComponent<Animator>();
    }

    public void BottunPressed()
    {
        UnitSpawner();
    }

    private void Update()
    {
        GoldCountDownTimer -= Time.deltaTime;

        if (GoldCountDownTimer < 0 || GoldCountDownTimer == 0)
        {
            GoldCountDownTimer = ResetTimer;
            PlayerGold += 4;
        }

        CounterTroop.text = TroopCounter.ToString() + "/" + PlayerMaxTroops;
        CounterGold.text = PlayerGold.ToString();
    }

     void UnitSpawner()
    {
        if (PlayerGold == 5 || PlayerGold > 5 && TroopCounter < PlayerMaxTroops)
        {
            Instantiate(FootmanObj, BaseSpawnPoint.position, BaseSpawnPoint.rotation);
            PlayerGold -= 5;
            TroopCounter++;

            Debug.Log("Ally spawned " + TroopCounter);
        }

        else
            return;
    }
}