Setting a prefab clone as a variable in code

So in my game I only have one gameobject and that is a spawner. What is does is spawn an arena, player, and defensemen. So what is supposed to happen is the defensmen are supposed to follow the player when the game starts. The problem I am having is when everything spawns I can’t get the player prefab clone to become the target for the defenseman.

Here is the code for the Player:

var speed : int = 1; // Adjust to make your NPC move however fast you want.

function Start () {

	GameObject.FindGameObjectsWithTag("Defenseman").SendMessage("SetPlayer");

}
 
 function Update ()
 {
   transform.Translate(Vector3.forward * speed * Time.deltaTime);
 }

Here is the code for the Defensemen:

#pragma strict
var target: Transform; // drag the target here
var speed: float = 5.0; // object speed
private var moving = false; // object initially stopped
private var dir: Vector3;
private var plChar : GameObject;
     
     
function Start () {
}
     
function SetPlayer () {
     
	target = GameObject.FindWithTag("Player").transform;
     
}
     
function Update () {
    dir = target.position - transform.position; // calculate the target direction...
    moving = true; // and enable movement
      
    if (moving){ // if movement enabled...
         // move the object in the calculated direction (world coordinates):
         transform.Translate(dir * speed * Time.deltaTime, Space.World);
       }
     
     
     
 }

So what I thought is when the player spawns he could use .SendMessage to the defensmen to use the SetPlayer function. In the SetPlayer function in the Defensmen script it basically says find anyone with the tag Player and make that the target. Well this doesn’t work. When I start the game the defensemen just stay still and I get a few errors. They are either “UnityEngine.GameObject.SendMessage” or “Object Reference Not set to an Instance of the Object”. If anyone could help me find a way to set the player that spawns in the target for the Defesnmen that woudl be great.

First script reworked

var speed : int = 1; // Adjust to make your NPC move however fast you want.

private vat defenseMans : GameObject; 

 function Start () {
 
    defenseMans = GameObject.FindGameObjectsWithTag("Defenseman");
    for (var defenseMan : GameObject in defenseMans){
       var defManScr : DefenseManScriptName = defenseMan.GetComponent(DefenseManScriptName);
       defManScr.active = true;
    }
 }
  
  function Update ()
  {
    transform.Translate(Vector3.forward * speed * Time.deltaTime);
  }

Second script:

 #pragma strict
  var target: GameObject; // drag the target here
  var speed: float = 5.0; // object speed
  private var moving = false; // object initially stopped
  private var dir: Vector3;
  private var plChar : GameObject;
  public var active : boolean;
       
       
  function Start () {
  }
       
  function SetPlayer () {
       
      target = GameObject.FindGameObjectWithTag("Player");
       
  }
       
  function Update () {
      if (active){
         SetPlayer();
      }
      dir = target.transform.position - transform.position; // calculate the target direction...
      moving = true; // and enable movement
        
      if (moving){ // if movement enabled...
           // move the object in the calculated direction (world coordinates):
           transform.Translate(dir * speed * Time.deltaTime, Space.World);
         }
       
       
       
   }

The problem is in player script:
FindGameObject and FindGameObjects are not same.

GameObject.FindGameObjectsWithTag(“Defenseman”); //This return array of GameObject.

you have to do this:

var listOfDefenseman : GameObject[] = GameObject.FindGameObjectsWithTag("Defenseman");
for (defman : GameObject in listOfDefenseman) {
	defman.SendMessage("SetPlayer");
}

If you have one defenseman script use this:

GameObject.FindGameObjectWithTag(“Defenseman”).SendMessage(“SetPlayer”);