Animator not playing animation on function call from other script

I have a function that plays an animation. It is correctly setup up because when I call it from Start () function, it does play the animation. But, when I call it from another script, the animation simply does not play it.

var animator : Animator;
    
function Start () {       
     SwapColors2And5();
}
 
 function Update () {
    	
}
 
function SwapColors2And5 () {
    	Debug.Log("2 and 5 called");
    	animator.Play("colorSwap2And5");
}

This works. But when I try to call SwapColors2And5 from another script, the animator doesn’t play it, even though Debug is logging “2 and 5 called”.

Here’s my call from the other script:

var enemyScript = enemy.GetComponent(enemyController); //this is where I get the actual script
	
if (randomNumber % 2 == 0 && randomNumber % 3 == 0) {
			enemyScript.SwapColors2And3();
		} 

The function is being called, Debug.Log works, but the animator.play does not.

I solved my problem. I had to use a different approach, instead of calling the animator from the other script, I get the value of random Number and call the animator inside the main script. Oddly, seems that you can’t control animator from other scripts using Get Component.

//I use this to return random number value to my enemy script

function ReturnTheNumber () {
//Call from enemyController
	return randomNumber;

}

//And in the enemy script:

 public var enemySpawnScript : enemySpawn;

private var randomNumber : int;
private var animator : Animator;


function Start () {
	
	enemySpawnScript = GameObject.FindGameObjectWithTag("Background").GetComponent(enemySpawn);
	animator = this.gameObject.GetComponent(Animator);
	randomNumber = enemySpawnScript.ReturnTheNumber();
		
	if (randomNumber % 2 == 0 && randomNumber % 3 == 0) {
			SwapColors2And3();
		}