Script won't do things after loading a new level

In my script, it’s supposed to load a new level, then instantiate a prefab. The level loading works, but it ALWAYS tries to do the other stuff before changing the level, and the prefab goes away.

function Update () {
	if (//some stuff//) {
		displayKickDialogue();
	}

}

function displayKickDialogue () {
	Application.LoadLevel("titlemenu");
	//Instantiate(Resources.Load("KickDialogue"));
	
	
	Screen.showCursor = true;
}

function OnLevelWasLoaded () {
	Instantiate(Resources.Load("KickDialogue"));
	
}

I also tried using OnLevelWasLoaded and it still shows the thing before loading the new level.

The scripts will get destroyed when loading a new Scene.

Here is the scripting reference.

You have to add DontDestroyOnLoad(transform.gameObject); somewhere in your code.
For example in function Awake() or function Start()

Hi! I think the object what is contain the script is deleted (disabled) when the new level loaded, that’s why it dont works.
Try DontDestroyOnLoad.