I need instantiated game objects to move once they're instantiated

My game requires the player to move a Blob around a 2D map and eat the humans that are running around, the problem is the humans don’t move.
I’m trying to get this chunk of code to work as a base to build from.

----

(Unityscript)
This is supposed to spawn a human and make it move to the left:

//Speed the humans run at
    var Hspeed : float = 90;
    var human : GameObject;
    function Update() {

	//Makes random numbers for the X and Y positions for the spawning humans
	var randX = Random.Range(-725, 590);
	var randY = Random.Range(-400, 375);
	//Makes random number for the probability of a human spawning
	var spawnProb = Random.Range(1, 50);
	
	//Spawns a Human at a random position
	//Moving Left
	if (spawnProb == 3) {
			var person : GameObject = Instantiate(human.gameObject, Vector3 (randX, randY, 1), Quaternion.identity);
			human.transform.Translate(Vector2.right*Hspeed*Time.deltaTime);
		}
  }

----

The humans spawn without any errors or problems but they don’t move.

Thanks for the help

Well taht’s is realy weird code, but any way.

  1. var person : GameObject = Instantiate … you just created new humanoid and pu reference on it into person variable, but than you moving your soursed game object human.transform.Translate, not the new one witch created, you should move person not human

  2. You do that in update loop, so event if you will do it with the right object, you will do it just in one frame (frame when “spawnProb == 3” and have spawn it), that men’s that you will move it just once and even will not see this

Wahi you should do

var spawnProb = Random.Range(1, 50);
 if (spawnProb == 3) {
     Instantiate(human.gameObject, Vector3 (randX, randY, 1), Quaternion.identity);
    }
 }

modifay spawn section like this, it wierd any way but sould work.

  1. Wrine new scrip “HumanoidMotion” - attach it to soursed humanoid that you have var human : GameObject, write motin code in Update loop of that attacked script. Good luck bro.

That script looks like a spawn manager. In that case you would want a separate script that moves whatever object it is attached to. Example: make a separate script with this:

var Hspeed : float = 90;
function Update(){
transform.Translate(Vector2.right*Hspeed*Time.deltaTime);
}

and attach it to your human prefab.
The reason your humans do not move is because on the frame that the human is created it moves a tiny bit, and it does not update any longer because spawnProb is not equal to 3 the following frame. In order to move all the time, do what I mention above.

Thanks, that definitely helped but I still run into a problem. My goal is to have the humans run in a randomly chosen direction (up, down, left, right) and keep going in that direction until they run into something (then they would change direction). Here is what I have for that right now:

//Decides which direction the humans will run
function Update() {

	var randDir = Random.Range(1,4);
	
	//Right
	if (randDir == 4) {
		person.transform.Translate(-Vector2.right*Hspeed*Time.deltaTime);
	}
	
	//Left
	if (randDir == 3) {
		person.transform.Translate(Vector2.right*Hspeed*Time.deltaTime);
	}
	
	//Up
	if (randDir == 2) {
		person.transform.Translate(Vector2.up*Hspeed*Time.deltaTime);
	}
	
	//Down
	if (randDir == 1) {
		person.transform.Translate(-Vector2.up*Hspeed*Time.deltaTime);
	}
	
}

This makes the humans basically just shake around. I understand why it does this, but does anybody know what I could do to get going in the right direction?