DontDestroyOnLoad is not working

i am building a game where player will pick star to increase scores. In the first level it goes well but when the player enter the next level then all scores and lives get reset. I used DontDestroyOnLoad but still its not working.here is my code

function Awake(){
DontDestroyOnLoad (this);
var current=Application.loadedLevelName;
if(current==“lavel 1”) {
ScoreToShow = GameObject.Find(“GUI/txt-score”).GetComponent(GUIText);
LifeToShow=GameObject.Find(“GUI/Life text”).GetComponent(GUIText);
Score =0;
Life=3;
UpdateScoreText();
UpdateLifeText();
}

}
function Start() {
DontDestroyOnLoad(gameObject);
}
i have tried the DontDestroyOnLoad(this) on awake and start function to get a result.I have applied all probablities. please help me fixing this problem

Instead of using DontDestroyOnLoad, use static variable for score and life OR post whole script to understand your logic.

my logic is nothing special, i just want all the data achieved in the first level to be carried on second level. can you give me a better solution how to carry player data like score,life, etc to the next level.

Try to save the whole gameObject rather than just the current script:

DontDestroyOnLoad(gameObject);

I tried this.the player doesn’t destroy but the scores and life get reset.

Then this might not be related to the object being destroyed but instead the values might get overwritten from somewhere else. Did you check that?

in the first level the score=0 and life=3. but after crossing the first level when the second level loaded the player doesn’t destroy but all the scores becomes 0 and life become 3.If you have alternate way to fix this please help me. I am stuck in this position and tried for three days but no result for better understanding i am giving my full player code.i used player prefab.

var horizontalSpeed : float = 2.0;
var verticalSpeed : float = 2.0;
var speed:float=40;
private var ScoreToShow:GUIText;
private var LifeToShow:GUIText;
private var Score:int;
private var Life:int;
Screen.showCursor = false;
function Awake(){
DontDestroyOnLoad(gameObject);
var LavelName=Application.loadedLevelName;
if(LavelName==“lavel 1”){
ScoreToShow = GameObject.Find(“GUI/txt-score”).GetComponent(GUIText);
LifeToShow=GameObject.Find(“GUI/Life text”).GetComponent(GUIText);
Score =0;
Life=3;
UpdateScoreText();
UpdateLifeText();
}
}
function Update ()
{

transform.Translate(Vector3.forward * Time.deltaTime*speed);

var h : float = horizontalSpeed * Input.GetAxis (“Mouse X”);
var v : float = verticalSpeed * Input.GetAxis (“Mouse Y”);
transform.Translate (h, v, 0);
transform.position.x=Mathf.Clamp(transform.position.x,-8,8);
transform.position.y=Mathf.Clamp(transform.position.y,-9,7);

}
function OnTriggerEnter (other : Collider) {
if(other.tag== “Barrier”){
Life-=1;
UpdateLifeText();
transform.position=Vector3(0,0,-100);

}
if(other.tag== “Bonus”){
Score+=10;
UpdateScoreText();
Destroy(other.gameObject);

}
if(other.name==“1 complete”){
Application.LoadLevel(“lavel 2”);
}
}
function UpdateScoreText(){
ScoreToShow.text = Score.ToString();
}

function UpdateLifeText(){
LifeToShow.text=Life.ToString();
}
function OnGUI(){
if(Life<0){
Application.LoadLevel(“Menu main”);
}
}