question

brendan avatar image
brendan asked

Get position for player in leaderboard

Question from a developer:

In Cloud Script, I'm trying to retrieve the current player's leaderboard position. This is what I'm calling in Cloud Script:

var leaderboardPosition = server.GetLeaderboardAroundUser({
                
PlayFabId: currentPlayerId,
StatisticName: "Trophies",
MaxResultsCount : 1
});
log.debug("leaderboardPosition Position:");
log.debug(leaderboardPosition.Position);

Though the returned log data is null. Where am I going wrong?

CloudScriptLeaderboards and Statistics
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

The data returned by that call is actually an array of entries, since it can return multiple players. So instead of leaderboardPosition.Position, what you actually want is leaderboardPosition.Leaderboard[0].Position.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.