đ Leaderboard
The Leaderboard class is designed to create and manage leaderboards in a game. It utilizes a UI template for player entries, updates rankings based on provided data, and listens for events to keep leaderboards synchronized.
Dependenciesâ
- Framework: The framework containing shared modules.
- Shared: Shared modules such as
BigNum,Functions,Services,Network, andAbbreviation. - Assets: Asset folder containing GUI elements.
Constructorâ
Leaderboard.new(part: BasePart, currency: string)â
- Creates a new instance of the
Leaderboardclass. - Parameters:
part: The BasePart to which the leaderboard UI will be attached.currency: The currency type associated with the leaderboard.
Methodsâ
Leaderboard:Update(rankings: {})â
- Updates the leaderboard UI based on the provided rankings data.
- Clears existing entries and creates new player entries.
Leaderboard:CreatePlayer(rank: number, userId: number, amount: number)â
- Creates a new player entry in the leaderboard UI.
- Populates the entry with user information and ranking details.
Leaderboard:Clear()â
- Clears all player entries in the leaderboard UI.
findLeaderboards()â
- Finds and initializes leaderboards in the game environment.
- Creates instances of the
Leaderboardclass for each valid leaderboard part.
Eventsâ
-
LeaderboardUpdated(currency: string, rankings: )
- Triggered when the server sends updated leaderboard data.
- Updates the corresponding leaderboard instance with the new rankings.
-
DataLoaded()
- Triggered when the game data is loaded.
- Calls
findLeaderboards()to initialize leaderboards.