Getting players rank from game center

I’m trying to get the players rank, the only way I can see to do this is to cycle through all scores and find the match. With millions of score entries, this takes ages.

is there an easier way?

heres the code I’m currently trying, it doesn’t return a rank.

    public int GetUserRank()
    {
        string user = Social.localUser.id;
        int rank = 0;
        Social.LoadScores("scoreBoardName", scores =>
        {
            if (scores.Length > 0)
            {
                Debug.Log("Retrieved " + scores.Length + " scores");

                //Filter the score with the user name
                for (int i = 0; i < scores.Length; i++)
                {
                    if (user == scores[i].userID)
                    {
                        rank = scores[i].rank;
                    }
                }
            }
            else
            {
                Debug.Log("Failed to retrieved score");
            }
        });
        return rank;
    }

Social.LoadScores runs asynchronously. Meaning, it’s still running when you hit your return statement of return rank. If you need the rank, you need to structure your code to use it inside of the LoadScores callback function.