> For the complete documentation index, see [llms.txt](https://sprites-organization.gitbook.io/ezstatz-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sprites-organization.gitbook.io/ezstatz-documentation/api-reference/data-functions.md).

# Data Functions

A brief summary of all available DataStore related functions.

{% hint style="success" %}
Recommended if you would like to keep data saved for the next time a player comes to play your game again.
{% endhint %}

{% hint style="warning" %}
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.
{% endhint %}

### `getData(player: Player): {any}`

Returns the provided `Player`'s leaderboard data.

{% hint style="warning" %}
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.
{% endhint %}

#### Example

```lua
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.

{% hint style="warning" %}
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.
{% endhint %}

#### Example

```lua
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.

{% hint style="warning" %}
Just like the 2 functions above, `eraseData()` uses `RemoveAsync()`, which is also another Datastore method. Wrapping the function in a `pcall()` is strongly recommended.
{% endhint %}

{% hint style="danger" %}
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.
{% endhint %}

#### Example

```lua
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
```
