π Leaderboard
Leaderboard module to create leaderboards for currencies made in the game.
Getβ
This function either creates a new leaderboard, if one with the currency does not already exist, or, it returns the class for the already existing leaderboard.
Class being the metatable holding all methods to interact with the leaderboard.
local Framework = require(path).GetServer()
local Leaderboard = Framework.Leaderboard
local WinsLeaderboard = Leaderboard.Get("Wins") -- Takes in the currency as first parameter.
GetServerLeaderboardβ
Returns all of the players on the leaderboard that are in the current server.
WinsLeaderboard:GetServerLeaderboard()
GetStoredβ
Returns every player on the leaderboard.
WinsLeaderboard:GetStored()
Initialiseβ
Initialises the update loop to update the leaderboard data.
WinsLeaderboard:Initialise()
Storeβ
Adds new data to the leaderboard from a table.
local newUsers = {
[213106169] = 100,
[213106169] = 100,
[213106169] = 100,
}
WinsLeaderboard:Store(newUsers)
GetRankingsβ
When interacting with the leaderboard, it's better to use this to get the current players on the leaderboard as it returns a cached table, avoiding the use of GetAsync and yielding, unless you use promises for the asynchronous operations support.
Retrieves a cached table of all the current players on the leaderboard.
WinsLeaderboard:GetRankings()
BindToUpdateβ
Asigns a function to be called once the leaderboard updates.
local WinsLeaderboard = Leaderboard:Get("Wins")
function leaderboardUpdated(rankings)
for i, v in rankings do
print(`{i}: {v}`)
end
end
WinsLeaderboard:BindToUpdate(leaderboardUpdated)