2 errors making a loading scene

I need to do a loading scene that load different level from saves,

i made a empty scene only with the main camera and added to it :

loading.js:

#pragma strict
function Start () {
var livello : String;

if(PlayerPrefs.GetString("Livello") != null)
   livello = PlayerPrefs.GetString("Livello");
else 
Application.LoadLevel("main menu");

if(livello.Equals("livello 2"))
   Application.LoadLevel("main menu 2");   
}

With this code unity gives me 2 errors:

GetString can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.

ArgumentException: GetString can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.PlayerPrefs.GetString (System.String key) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/PlayerPrefsBindings.cs:73)
loading..ctor () (at Assets/Scripts/loading.js:2)

I believe the variable you call livello is local to start and not a “global” in your class/script…

var livello : String;

try moving that outside your function Start()

Not sure if this is the reason, but I think it is.

I solved my problem, i forgot to add an else to load main level, The two errors weren’t in the script that i posted, they were a console “log” that i don’t delete