- Home /
Lootlocker Live Leaderboard not working
I'm trying to implement a leaderboard into my game using the LootLocker API. It works when I use a stage leaderboard, however, I can't get it to work using a live leaderboard. I'm still new to game development so I might be doing something wrong. I keep getting the error that the leaderboard doesn't exist even though I'm giving it the id that's within LootLocker, here's my code: public static Leaderboard instance; //Handling showing uploading scores
int leaderboardID = 2892; //used to reference leaderboard
[SerializeField] private TextMeshProUGUI playerNames;
[SerializeField] private TextMeshProUGUI playerScores;
void Start()
{
if(instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
} else
{
Destroy(gameObject);
}
if (playerNames != null || playerScores != null)
{
return;
}
}
//Coroutine to wait for the LoginCo before executing
public IEnumerator SubmitScoreCo(int score)
{
bool done = false;//used to wait until server is done
string playerID = PlayerPrefs.GetString("PlayerID"); //who is uploading score?
//pass in the player, their score, and the leaderboard this information is going to
LootLockerSDKManager.SubmitScore(playerID, score, leaderboardID, (response) =>
{
if(response.success)
{
Debug.Log("Successfully uploaded score");
done = true;
} else
{
Debug.Log("Couldn't upload score: " + response.Error);
done = true;
}
});
yield return new WaitWhile(() => done == false);
}
public IEnumerator FetchHighscoresCo()
{
bool done = false;
//getting the top 10 scores from the leaderboard
LootLockerSDKManager.GetScoreListMain(leaderboardID, 10, 0, (response) =>
{
if (response.success)
{
string tempPlayerNames = "";
string tempPlayerScores = "";
LootLockerLeaderboardMember[] players = response.items;
//set the names and scores from players
for (int i = 0; i < players.Length; i++)
{
tempPlayerNames += players[i].rank + ". ";
//does the player have a name?
if (players[i].player.name != "")
{
tempPlayerNames += players[i].player.name;
}
else
{
tempPlayerNames += players[i].player.id;
}
tempPlayerScores += players[i].score + "\n\n";
tempPlayerNames += "\n\n";
}
done = true;
if(playerNames != null || playerScores != null)
{
playerNames.text = tempPlayerNames;
playerScores.text = tempPlayerScores;
}
}
else
{
Debug.Log("Couldn't display leaderboard: " + response.Error);
done = true;
}
});
yield return new WaitWhile(() => done == false);
}
Any help would be appreciated, and thank you in advance.
Answer by JohannesLoot · May 05 at 06:23 AM
Hi LootLocker employee here! I think that the issue might be that you are trying to fetch the leaderboard from the stage environment while development mode is off.
Leaderboards are different between Live and Stage (development mode on/off) environment, so you need to create a new Leaderboard for the Live environment as well. You will get a new leaderboadID for the live leaderboard, and need to use that instead. If you instead use the leaderboard key, you can give the leaderboard in stage and live the same leaderboard key and then you don't need to swap the leaderboard identifier when switching between the environments.
Hope this helps :) If you have more questions you can join our discord-channel: https://discord.lootlocker.io
/Johannes, Game Developer, LootLocker