API Reference
Creator Functions
createLeaderstatsObject(player: Player): Folder
createLeaderstatsObject(player: Player): Folder
Creates a Leaderstats folder into the specified Player object and returns it.
Example
The code below will create a new leaderstats object each time a player joins the game, and will print it's Name
property and the Player
's name that the Folder is being parented to.
createValue(player: Player, name: string, valType: valueType): ValueBase
createValue(player: Player, name: string, valType: valueType): ValueBase
Creates and returns a Value
based on the given valType
Below is a list of Value objects currently supported by the valType parameter.
Most Value objects are not supported at this time, however more support will come as updates follow.
int
IntValue
str
StringValue
Example
Getter Functions
getLeaderstats(player: Player): Folder
getLeaderstats(player: Player): Folder
Returns a Player's leaderstats folder if they have one.
Example
Setter Functions
set(player: Player, name: string, value: any)
set(player: Player, name: string, value: any)
Sets the given Player
's value of name
to the specified value
Example
The name
parameter must be apart of the Player
's leaderstats folder.
incrementValue(player: Player, name: string, delta: number)
incrementValue(player: Player, name: string, delta: number)
Increases the Player
's provied stat name
by the provided delta
number.
Example
decrementValue(player: Player, name: string, delta: number)
decrementValue(player: Player, name: string, delta: number)
Similar to incrementValue()
, except it decreases.
Example
Comparison Functions
isGreaterThanOrEqual(player: Player, value, num): boolean
isGreaterThanOrEqual(player: Player, value, num): boolean
Returns whether or not value
's value is greater than or equal to num
.
Example
isLessThanOrEqual(player: Player, value: ValueBase, num: number): boolean
isLessThanOrEqual(player: Player, value: ValueBase, num: number): boolean
Same as isGreaterThanOrEqual()
, however it'll do the exact opposite, instead checking if the provided value
is less than or equal to num
.
Example
isGreaterThan(player: Player, value: ValueBase, num: number): boolean
(player: Player, value: ValueBase, num: number): boolean
Returns true if the given value
's Value
property is greater than num
. Otherwise, returns false.
Example
isLessThan(player: Player, value: ValueBase, num: number): boolean
isLessThan(player: Player, value: ValueBase, num: number): boolean
Similar to isGreaterThan()
, it will instead return true if the value's Value property is less than num
Example
Data Functions
Recommended if you would like to keep data saved for the next time a player comes to play your game again.
If you plan on testing your scripts that use the module in Studio, playtest your game in the Roblox client first. Otherwise, the Player Data functions may not work as intended.
getData(player: Player): {any}
getData(player: Player): {any}
Returns the provided Player
's leaderboard data.
This function contains the GetAsync()
method which can have a chance to fail. Wrapping the function in a protected thread (a.k.a pcall()
) is strongly recommended.
Example
saveData(player: Player)
saveData(player: Player)
Saves all of the current values inside of the Player
's leaderstats folder into the datastore.
Just like getData()
, saveData()
has the SetAsync()
Datastore function, which can also have a chance to fail. Wrapping the function in a pcall()
is strongly recommended.
Example
eraseData(player: Player): {any}
eraseData(player: Player): {any}
Clears a Player's Datastore key if there's any data present within it.
Just like the 2 functions above, eraseData()
uses RemoveAsync()
, which is also another Datastore method. Wrapping the function in a pcall()
is strongly recommended.
If there is no systems in your game that allows players to recover data, this function's actions CANNOT be reversed. Only use this function under exceptional circumstances if there's no data recovery systems in place.
Example
Last updated