Heyo, before I explain my module and the mechanics of it, I’d like to mention that this is my first resource/contribution on here. If you have any criticism feel free to throw it all at me. Any criticism on how I could structure/compose my next resource/contribution would also be greatly appreciated! Thanks
Quick disclaimer to some
If you’re unfamiliar with programming, I suggest looking at a youtube tutorial instead of this post. Why? Well I think it’d be a little daunting to comprehend the module in its entirety. However, if you insist on using this module, feel free to ask for help below if you’re stumped
Leaderboard API:
-
.new(contentData: leaderboardData)
– Constructs a new leaderboard class. -
:DisableLocalTesting()
– Stops “test accounts” saving to the leaderboard. Useful for when you’re running a local server and don’t want “test accounts” to append to the leaderboard. -
:Clear()
– Clears all the icon templates in the leaderboard icon parent. -
:Load()
– Creates brand new icon templates which are displayed on the leaderboard icon parent. -
:Update()
– Exactly the same as doing:Clear() return :Load()
. -
:Append(userId: number, value: number)
– Appends a value to the leaderboard given auserId
andvalue
. Equivalent to aSet
method. -
:Erase(userId: number)
– Removes a value from the leaderboard given auserId
. Just a reminder, this method shouldn’t be used too often. Equivalent to aRemove
method. -
:ClearCache()
– Clears the cache if you’re using one. -
:AutoUpdate(updateTime: number)
– Creates a loop to “auto update” the leaderboard everyx
seconds. Equivalent to using:Update()
in a while loop. -
:BreakAutoUpdater()
– Stops the auto updater. -
:AttachRefreshTimer(refreshTimer: TextLabel)
– If you have aTextLabel
which should display the time until the next “refresh”, just pop it into the function and you’re good
Okay, the API is out of the way. Now, what is this “contentData” in the constructor function?
The “contentData” is a table which contains data that the leaderboard uses to operate properly.
Here’s a list of all the content data:
-
datastoreKey
– The datastore key used for saving, loading and updating the leaderboard. This is a string type and the leaderboard will throw an error if it’s not. -
leaderboardIconParent
– The parent for any created icon templates. This has to be anInstance
type. -
iconTemplate
– The module associated to creating the actual icon template. The base icon template can be found in a module within the main module. -
format
– How the value is altered. There are three built-in formats: “Comma”, “Abbreviate” and “Time”. You can also pass afunction
if you want to have your own formatting function. -
lines
– This is the max amount of icon templates that can appear on the leaderboard. -
descendingOrder
– Whether or not the icon templates appear in ascending or descending order. -
displayNamesEnabled
– Should “DisplayNames” be shown in the icon template. -
showDisplayNameIfSameAsName
– If a player’s “Name” and “DisplayName” are the same, should the “DisplayName” still be displayed. e.g. Inpultion(@Inpultion) -
thumbnailsEnabled
– Whether or not player icons will be displayed. -
thumbnailCache
– Whether or not to save player icons into a cache, so that the next time the leaderboard refreshes, it can be collected from a cache instead of being acquired again. -
userDataCache
– Whether or not to save player data into a cache, so that the next time the leaderboard needs to request a “DisplayName” and or “Name” it will acquire it from the cache instead. -
debug
– Whether or not warnings are displayed or not. Enabling this feature may help with seeing if the roblox datastores are experiencing issues.
Default contentData:
-
datastoreKey
– No default value set. This is a required field to fill. -
leaderboardIconParent
– No default value set. This is a required field to fill. -
iconTemplate
– Default icon template constructor function. -
format
– “Comma”. -
lines
– 25. -
descendingOrder
– false. -
displayNamesEnabled
– true. -
showDisplayNameIfSameAsName
– false. -
thumbnailsEnabled
– false. -
thumbnailCache
– true. -
userDataCache
– true. -
debug
– false.
Right, time to elaborate on a couple of things.
- If you’re looking to create a custom icon template, make sure that you pass the “iconTemplate” as a
function
, as such:
-- modules
local leaderboardModule = require(14717967724)
-- functions
local newLeaderboard = leaderboardModule.new({
iconTemplate = function(name, value, rank, displayName, thumbnail, showDisplayNameIfSameAsName)
local iconTemplateFrame = Instance.new("Frame")
-- blah, blah, blah. Create the icon stuff here.
return iconTemplateFrame
end
})
Make sure that the function also holds those same arguments; in that order, or things may not work as you intend them to. Make sure to return the icon template “container”, otherwise the leaderboard won’t parent the icon template to the leaderboard.
- When creating a custom formatter. Make sure that you pass “format” as a
function
, as such:
local newLeaderboard = leaderboardModule.new({
format = function(value: number)
return value -- Or whatever you change the value to.
end,
})
Keep in mind that if the format function doesn’t return a number, it may pose an error, breaking the leaderboard.
Where can I get the module? Right here. You can alternatively do require(14717967724)
as a shortcut.
( For now there isn’t a github sowry )
I’d also like to thank @okeanskiy for one of the built-in formatters ( The number abbreviator ) You can check out his video on number abbreviating!
Is credit required? Not at all. Credit would be nice, but again, it’s not something I’ll run after you for… (
or so you think >:) )
p.s, Here’s a quick video showing a basic leaderboard template in action. (As well as an uncopylocked place)
Place.
If you have any questions, critiques or suggestions which may pose benefit to this resource, feel free to let me know below.
Tell me what you think about the module:
- Great module, no issues.
- It’s okay.
- Pointless module.
0 voters