update function problem

my problem is that i keep getting this error MissingReferenceException: The object of type ‘Transform’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.

i understand that one of my scripts has an update function and is still trying to find this object after it got destroyed …how can i make the script stop running the update function after the object (cube) gets destroyed???or better yet how can i fix this error??
the script is… var target : Transform;function Update () {var other = gameObject.GetCompo - Pastebin.com the “question1” thing is the script that it opens once its close to the player

Most likely, the reason for this is due to the use of GetComponenet within the Update() function.
You should call the getComponent only once before starting the update (enable=true starts the script…).
This way, you address any errors of this kind before doing updates and you avoid a bad performance, as the GetComponent function is an expensive one.
Do something like this:
in the scope of the class:

private var other;

void Start()
{
 other = gameObject.GetComponent("question1");
}

then use other in update without the need to constantly call GetComponent.

Also, if you know in advance the type of the variable other - define it when you define the variable so you can catch errors before running your program (e.g. if “other” is a variable of type “GameObject” define it like this:

private var other : GameObject;

It probably would be something like this, since I assume you wish the to change the state of the question1 component depending on the changing distance (doesn’t the distance change in your game?)

var target : Transform;
private var other;

void Start()
{
     other = gameObject.GetComponent("question1");
}

Update()
{
    if ( Vector3.Distance(target.position, transform.position ) <= 5)
       other.enabled = true;
    else
       other.enabled = false;
}

Also, notice that I used only one call to Vector3.Distance since you don’t need the second one. Once you have the distance, using if…else you can decide what to do with it.
Your distance is either bigger then 5, equals 5 or smaller then 5.
If you’d want to do something else when it equals 5 you could still calculate the distance once and use the memory to test, like this:

update()
{
   var distance : float = Vector3.Distance(target.position, transform.position );

   if ( distance < 5 )
     other.enabled = true;
   else if ( distance > 5 )
     other.enabled = false;
   else // this means distance == 5 and you don't need to specify the condition now
   {
     // do something else if you wish
   }
}