I can't change a boolean from another script on another object from my script

I have an object “Player” which can talk to other objects. When I talk I want to disable my movement abilities, but for some reason my movement doesn’t disable. This is the script (the script is on the object, which Player can talk to):

var isMoving : boolean;
var talkMessage : String[];
var displayText : String;
var showText : boolean;

function OnGUI () {
	if(showText) {
		GUI.Label (Rect (Screen.width/2, Screen.height/10, 500 ,20), "" + displayText);
	}
}

function talk () {
	
	showText = true;
	for(var i=0;i < talkMessage.Length;i++) {
		displayText = talkMessage*;*
  •  yield WaitForSeconds(2);*
    
  • }*
  • showText = false;*
    }

function Update () {

  • var Sprite = gameObject.GetComponent (AshAnimation);*

  • var other : Player1;*

  • other = gameObject.Find(“Player”).GetComponent(Player1);*

  • if(!isMoving) {*

  •  Sprite.totalCells = 1;*
    
  • }*

  • if(showText) {*

  •  other.disableMove = true;*
    
  • }*

  • else {*

  •  other.disableMove = false;*
    
  • }*
    }
    Player1 is the script with the variable disableMove. For some reason it does not change the variable disableMove when I try. How can I rewrite this so it can change the variable?

Do you have this script on several objects in the game? Each instance of this script that’s not showing text will set the player’s disableMove to false.

I’d suggest moving all of the disable move logic to the talk method, as it’s related to that. That’ll also make sure that only the scripts that you’re actually talking to is doing something with your player’s ability to move.

function talk () {
    var other : Player1;
    other = gameObject.Find("Player").GetComponent(Player1);
    other.disableMove = true;
    showText = true;

    for(var i=0;i < talkMessage.Length;i++) {
        displayText = talkMessage*;*

yield WaitForSeconds(2);
}
showText = false;
other.disableMove = false;
}

function Update () {
var Sprite = gameObject.GetComponent (AshAnimation);

if(!isMoving) {
Sprite.totalCells = 1;
}
}
That should probably fix your problem. If not, then there’s something wrong in the player script.