Moving a gameObject to the position of an empty gameObject

I am exporting to flash and reloading the level when you die takes too much time. So, i am just moving the player back to the beginning point when you die.

I hard coded the position to send the player but that way i would have to re-write the script for each level to match the beginning points. So i am trying to save the position as a private variable.

So i have an empty game object at the beginning point of the level and when the player is in a situation that would cause death he moves to that position. However, there are different erros when i try different things. Below is the code i am using and i’ll put the error up for the currently problem with this attempt.

#pragma strict
var enableGUI : boolean = false;
private var respawnPoint : Transform; 

function Start () {

 respawnPoint = gameObject.FindWithTag("respawnPoint").transform;	
	
}
function OnTriggerEnter (hitPlayer : Collider) {
	
	
	
	if(hitPlayer.gameObject.tag == "Player") {

		enableGUI = true;
		Time.timeScale = 0;
		hitPlayer.transform.position = Vector3(respawnPoint.transform.position.x, respawnPoint.transform.position.y, respawnPoint.transform.position.z);
		
	}		
}

I am getting Null Exception Reference… but not to sure why since i have set the variable in start…

HELP! Frustrating.

You try respawnPoint = GameObject.FindWithTag(“respawnPoint”).transform;
not gameObject, true is GameObject; and check tag.

For future reference if anyone google searches this there is a better/easier way to do this:

You can just do it as:

function OnTriggerEnter (hitPlayer : Collider) {



    if(hitPlayer.gameObject.tag == "Player") {

       hitPlayer.transform.position = respawnPoint.transform.position;
}

}

Instead of defining all the axis separately.