📗
Ezstatz Documentation
  • 👋Welcome
  • ☑️Setting Up
  • 🪧Guide
    • 🥇Making Leaderboards via Ezstatz
    • 💾Managing Player Data
  • 🖥️API Reference
    • 📝Creator Functions
    • 🔄Getter Functions
    • ✅Setter Functions
    • ➕Comparison Functions
    • 💾Data Functions
  • ⚙️Settings Module
Powered by GitBook
On this page
  • Creator Functions
  • createLeaderstatsObject(player: Player): Folder
  • createValue(player: Player, name: string, valType: valueType): ValueBase
  • Getter Functions
  • getLeaderstats(player: Player): Folder
  • Setter Functions
  • set(player: Player, name: string, value: any)
  • incrementValue(player: Player, name: string, delta: number)
  • decrementValue(player: Player, name: string, delta: number)
  • Comparison Functions
  • isGreaterThanOrEqual(player: Player, value, num): boolean
  • isLessThanOrEqual(player: Player, value: ValueBase, num: number): boolean
  • isGreaterThan(player: Player, value: ValueBase, num: number): boolean
  • isLessThan(player: Player, value: ValueBase, num: number): boolean
  • Data Functions
  • getData(player: Player): {any}
  • saveData(player: Player)
  • eraseData(player: Player): {any}

API Reference

Creator Functions

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.

local Ezstatz = require(game.ServerScriptService:WaitForChild("Ezstatz"))

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Ezstatz:createLeaderstatsObject(player)
    print(leaderstats.Name, player.Name)
end)

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.

Parameter Name
Value Object

int

IntValue

str

StringValue

Example

-- Creating an integer based value
local cash = Ezstatz:createValue(player, "Cash", "int")

-- Creating a string based value
local rank = Ezstatz:createValue(player, "Rank", "str")

Getter Functions

getLeaderstats(player: Player): Folder

Returns a Player's leaderstats folder if they have one.

Example

local leaderstats = Ezstatz:getLeaderstats(player)

Setter Functions

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.

Ezstatz:set(player, "Cash", 10) -- Changes the player's cash to 10

incrementValue(player: Player, name: string, delta: number)

Increases the Player's provied stat name by the provided delta number.

Example

Ezstatz:incrementValue(player, "Cash", 5)

decrementValue(player: Player, name: string, delta: number)

Similar to incrementValue(), except it decreases.

Example

Ezstatz:decrementValue(player, "Cash", 10)

Comparison Functions

isGreaterThanOrEqual(player: Player, value, num): boolean

Returns whether or not value's value is greater than or equal to num.

Example

Ezstatz:isGreaterThanOrEqual(player, cash, 10)

--[[ 

If cash is greater than or equal to 10, this function returns true.
Otherwise, it'll return false.

]]--

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

Ezstatz:isLessThanOrEqual(player, cash, 10)

--[[ 

If cash is less than or equal to 10, this function returns true.
Otherwise, it'll return false.

]]--

isGreaterThan(player: Player, value: ValueBase, num: number): boolean

Returns true if the given value's Value property is greater than num. Otherwise, returns false.

Example

Ezstatz:isGreaterThan(player, cash, 10)

--[[ 

If cash is greater than 10, this function returns true.
Otherwise, it'll return false.

]]--

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

Ezstatz:isLessThan(player, cash, 10)

--[[ 

If cash is less than 10, this function returns true.
Otherwise, it'll return false.

]]--

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}

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

local success, data = pcall(function()
    return Ezstatz:getData(player)
end)
if success then
    if data then
        print(data)
    end
else
    warn("something went wrong.", data)
end

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

local success, message = pcall(function()
    Ezstatz:saveData(player)
end)

if not success then
    warn("something went wrong.", message)
end

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

local success, recoverable = pcall(function()
    return Ezstatz:eraseData(player)
end)

if success then
    if recoverable then
        print(recoverable)
    end
else
    warn("something went wrong.", recoverable)    
end
PreviousManaging Player DataNextCreator Functions

Last updated 1 year ago

🖥️