PlayerPrefs Highscore problem

Hey all im doing my first attempt at a playerPref highscore system and have run it to a little problem.

The problem is :

Argument Exception: GetString can only be called from the main thread.

I have googled the problem and i understand it has to do with code being outside of a function but i cannot work it out. Here is my code,

PlayerPrefs.GetString("RecordName",String.Empty);
PlayerPrefs.GetInt("RecordScore", -1);

function GetScore(recordIndex :int) :int

{
	var key = String.Format("RecordScore", recordIndex);
	return PlayerPrefs.GetInt (key, -1);
}

function SetScore (recordIndex:int,score:int)
{
	var key = String.Format("RecordScore",recordIndex);
	PlayerPrefs.SetInt(key,score);
}

function GetName (recordIndex:int):String
{
	var key = String.Format("RecoerName", recordIndex);
	return PlayerPrefs.GetString(key,String.Empty);
}

function SetName(recordIndex:int,name:String)
{
	var key = String.Format("RecordScore",recordIndex);
	PlayerPrefs.SetString(key,name);
}
var topName = GetName(0);
var topScore = GetScore(0);

Well, you have answered your own question. The first two lines, and the last two lines in your code above are not in any functions. Whilst it is okay to have variable declarations outside of functions, typically you should not have statements like that. Can’t you just pop them inside a Start() function? So:

var topName;
var topScore;

function Start()
{
    topName = GetName(0);
    topScore = GetScore(0);
}

I am not sure that your first two lines of code actually do anything.