NullReferenceException calling GameController Object, but it works on the other side of the IF...

I’m trying to call a function from the script in my GameController Object.

It works fine on one side of an IF, but on the other side it gives me
“NullReferenceException: Object reference not set to an instance of an object”

if (fooState == 2) {

    fooState = 0;
			
    myManagerScript.changeScore(pointValue);
		
} else {
			
    Debug.Log("is IF working at least?");
    myManagerScript.changeScore(pointValue);

}	

The debug log goes through. Note the call to the changeScore function is the exact same on either side. And if I comment out the 2nd one, the first works fine…

Any ideas? Thanks!

Okay, got it working. I changed the declaration of myManagerScript from private var to var

Though I’m still not sure why it would work (or not work) in one case and not the other?

changeScore is/was working fine, and fooState doesn’t do anything else. I actually wanted to call myManagerScript.resetCombo() when fooState != 2, I just replaced it with a function I knew was working first.