GameObject variable change for all of the objects

I know this is much to read but thanks for any help

There is 2-5 instantiated prefabs, they all have the same script named ‘walk’ and they all have a variable named stage, i made a for loop to respawn the prefabs(just a random number every time).
in the loop i have another random variable called randomX which responsible for the x position in the screen of the prefab. anyways if the its spawns on the left side of the screen i want the prefab to move to the right side by changing the stage variable(string) to “ltr” and if its spawns on the right side of the screen i want the prefab to move to the left side by changing it to “rtl”,this works but the problem is that its changing for all of the prefabs and not just to to the current prefab.

Spawn script:

for(var k : int = 0; k < respawnNum; k++){
    			var yRandomPos : float = Random.Range(6.98,-4.8);
    			xRandomPos = Random.Range(14.0, -14.0);
    			var position2: Vector3 = Vector3(xRandomPos, yRandomPos, -3.980108);
    			var pref2 : GameObject = Instantiate(prefab, position2, Quaternion.identity);
    
    			if(xRandomPos < 0){
    				pref2.GetComponent(walk).state = "ltr";
    			}
    			else if(xRandomPos >= 0){
    				pref2.GetComponent(walk).state = "rtl";
    			}

Walk script:(every instantiated prefab has this script)

	function Update(){
if(this.state == "ltr")
		transform.position.x += finalSpeed * Time.deltaTime;
	else if(this.state == "rtl") transform.position.x -= finalSpeed * Time.deltaTime;
}

finalSpeed is just a variable.

and yes i do use static variable to access it from other script

A variable only has to be declared “public” to be accessible from other classes, not “static”. “Static” means the variable is defined for that class, not independently to each instance of the class. So if “state” is declared static, it does change everywhere no matter where you change it.