🖥️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

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

getData(player: Player): {any}

Returns the provided Player's leaderboard data.

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.

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.

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

Last updated