Finding multiple gameobjects with tag error

Ok i have multiple enemies and multiple players in my scene. My problem was that when i an enemy killed a player they would stop searching for players tagged “playerguy”. So i tried changing GameObject.FindWithTag(“PlayerGuy”).Transform to GameObject.FindGameObjectsWithTag(“PlayerGuy”).Transform. Problem is i get this error

`Assets/TankMan/TankManScripts/EnemyScripts/Lvl1TerroristAI.js(29,74):
BCE0019: ‘transform’ is not a member
of ‘UnityEngine.GameObject’.

I understand why im getting this error, I just dont know how to fix it. If anyone can point me in the direction of fixing the problem that would be great.

    static var target1 : Transform;
    var moveSpeed : int = 6;  // chase speed
    var rotationSpeed : int = 1;  // speed to turn to the player
    var maxDistance : int = 10;  // attack distance
    var minDistance : int = 15;  // detection distance
    
    private var myTransform : Transform;
    
    function Awake() {
        myTransform = transform;
    }
    
    // Cache the controller 
    private var characterController : CharacterController; 
    characterController = GetComponent(CharacterController);
    
    function Start () { 
        target1 = GameObject.FindWithTag ("PlayerGuy").transform; 
        maxDistance = 2;
       
    }
    
    //------------------------------------------------------------------ 

    function Update(){
	if (target1 == null){
		target1 = GameObject.FindGameObjectsWithTag("PlayerGuy").transform;
        if (target1) {
        var dist = Vector3.Distance(target1.position, transform.position);
        if (dist > minDistance){  // if dist > minDistance: enters idle mode
            Idle(); 
        }
        else
        if (dist <= maxDistance) {  // if dist <= maxDistance: stop and attack		
            print ("Attack!");

        } 
        else {  // if maxDistance < dist < minDistance: chase the player
          //  print ("I found you "+ dist);
            myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
            Quaternion.LookRotation(target1.position - 										myTransform.position) , rotationSpeed * Time.deltaTime);
            
            // Move towards target
            characterController.Move(myTransform.forward * moveSpeed * Time.deltaTime);
            //
            //
        }
         if (dist <= maxDistance){
             myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
            Quaternion.LookRotation(target1.position - 										myTransform.position) , rotationSpeed * Time.deltaTime);
            }
    	}
    }
    }

//------------------------------------------------------------------

    var walkSpeed = 3.0; 
    var directionTraveltime = 2.0;
    var idleTime = 1.5; 
    var rndAngle = 45; 
    // enemy will turn +/- rndAngle
    
    private var timeToNewDirection = 0.0; 
    private var turningTime = 0.0; 
    private var turn: float;
    
    function Idle () { 
        // Walk around and pause in random directions unless the player is within range 
        if (Time.time > timeToNewDirection) { 
          // time to change direction? 
          if(Random.value > 0.5) // choose new direction 
              turn = rndAngle; 
         else { turn = -rndAngle; }
         turningTime = Time.time + idleTime; 
         // will stop and turn during idleTime... 
         timeToNewDirection = turningTime + directionTraveltime; 
         // and travel during directionTraveltime
       } 
       if (Time.time < turningTime) { 
           // rotate during idleTime... 
          transform.Rotate(0, turn*Time.deltaTime/idleTime, 0); 
       } else { 
          // and travel until timeToNewDirection 
          characterController.SimpleMove(transform.forward * walkSpeed); 
       }
    }

    function OnCollisionEnter(collision : Collision) { 
        transform.Rotate(0, turn*Time.deltaTime/idleTime, 0); 
    }

The problem is that you can’t access the Transform of a collection of GameObjects like that. You have an array of GameObjects that you found with FindGameObjectsWithTag(). To access a specific one, you need a specific GameObject, now there are a number of ways to do this.

 //The easiest
 var gOs = GameObject.FindGameObjectsWithTag("PlayerGuy");
 target1 = gOs[0].transform;
 //Get the first element in the array.

or convert the entire array. If you only need one element, this might be a waste of memory.

 //C#.
 var gOs = GameObject.FindGameObjectsWithTag("");
 var targets = Array.ConvertAll<GameObject , Transform>( gOs ,  x => x.transform );

hmm in runtime i get a null reference exception object reference not set to an instance of an object. and nothing shows up in the inspector to set…

Got help from someone on the scripting forums and figured it out

function Update () {

var target1 : Transform;
var gOs = GameObject.FindGameObjectsWithTag("PlayerGuy");

if (gOs.Length > 0) {
    var closestDistance : float=Mathf.Infinity;
   for(var g : GameObject in gOs) {
        var distance : float = Vector3.Distance (transform.position, g.transform.position);

        if (distance < closestDistance) {
            target1 = g.transform;
            closestDistance = distance;
        	}
        }
    }