Problem with destroying instanced objects

I want to instantiate an object and whenever I instantiates a new object I want objects who share the same tag with the new object to be destroyed. I got the following lines of code

instance = Instantiate(Resources.Load(targetModel)) as GameObject;
Destroy(gameObject.FindWithTag(instance.tag));

The problem as you might see by looking at the code is that the instance is destroyed right after its been made. I always want the latest instance to remain.

I tried to switch places like below, but then I get this error: “UnassignedReferenceException: The variable instance of ‘mousePosition’ has not been assigned.”

Destroy(gameObject.FindWithTag(instance.tag));
instance = Instantiate(Resources.Load(targetModel)) as GameObject;

So how do I solve this problem?

Store both instances in an array using FindGameObjectsWithTag() instead of FindWithTag(). Once both instances are in the array, check to see which is the latest (that would be the game object referenced by the variable named instance) and destroy the other one.

Hmm try…

var spawn : Transform;

function Start()
{
    var allGameObjs = GameObject.FindGameObjectsWithTag("Tag");
    for (var go in allGameObjs)
    {
        Destroy (go);
    }
    Instantiate (spawn);
}

thanks guys!
I used this solution thou:
http://answers.unity3d.com/answers/132077/view.html