transform.localscale.x not working

within the tutorial i am doing i am flipping an image and i am using the transform.localScale.x since i am flipping on the X axis. when in scene mode the image changes but when in game mode it doesn’t but when i look at the scale the numbers change but it doesnt flip. help please. here is the code for the game character image

var X : float;

function Start ()
{

X=transform.localScale.x; 

}

function Update () {

if(Input.GetKey("a"))
{
	transform.localScale.x = X; 
	
}
else if (Input.GetKey("d"))
{
	transform.localScale.x = -X; 
			
}

}

You should put your flipping code in the LateUpdate() function. Otherwise, the Animator might overwrite your localScale.

The Animator might move/scale the object during or after Update() and LateUpdate() will run after the Animator work is done.