> For the complete documentation index, see [llms.txt](https://docs.overdare.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.overdare.com/development/api-reference/classes/datastoreservice.md).

# DataStoreService

DataStoreService : `Instance`

## Overview

DataStoreService provides access to data storage in server environment.

## Properties

## Methods

### GetDataStore

Creates a new DataStore object based on the provided name and returns it. If it is called again with the same name, it reuses previously created instance.

#### Parameters

| `string` name      | The name of a DataStore object.                                                                                                            |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `string` scope     | A scope string used to distinguish keys within the DataStore. It can be left empty, and when provided, must be 50 characters or less.      |
| `Instance` options | An option instance used to specify additional behavior when creating the DataStore. If not specified, it is created with default settings. |

#### Return

| `GlobalDataStore` | The returned DataStore object. |
| ----------------- | ------------------------------ |

#### Code Samples

```lua
local DataStoreService = game:GetService("DataStoreService")
local GoldStore = DataStoreService:GetDataStore("PlayerGold")
```

### GetGlobalDataStore

Returns default global data store provided by system. The GetDataStore function must be used to access a separate data storage with a specific name.

#### Parameters

#### Return

| `GlobalDataStore` | The returned GlobalDataStore object. |
| ----------------- | ------------------------------------ |

#### Code Samples

```lua
local DataStoreService = game:GetService("DataStoreService")
local GlobalStore = DataStoreService:GlobalDataStore()
```

### GetOrderedDataStore

Returns the OrderedDataStore object that corresponds to the provided name and scope. OrderedDataStore can only hold integer values and allows retrieval sorted by the stored values, which makes it suitable for building leaderboards.

Calling it again with the same name and scope returns the same object that was returned previously. Calling it with the scope omitted and calling it with global as the scope return the same object.

This method can only be called from a server Script. Calling it from a client LocalScript raises an error.

**Important Notes**

* It uses storage separate from a DataStore retrieved with GetDataStore even when the name is identical, and the values never mix.
* Names, scopes, and keys are all case sensitive. Names that differ only in case are separate storage.
* In studio test environments, a temporary store is used without any additional setup, and the saved data is deleted when the test session ends.

#### Parameters

| `string` name  | The name of an OrderedDataStore object. Must be 50 characters or less.                                                                                                                                             |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `string` scope | <p>(Optional) A scope string used to separate storage within the OrderedDataStore.</p><ul><li>If omitted, global is used.</li><li>An empty string or a string longer than 50 characters raises an error.</li></ul> |

#### Return

| `OrderedDataStore` | The returned OrderedDataStore object. |
| ------------------ | ------------------------------------- |

#### Code Samples

```lua
local DataStoreService = game:GetService("DataStoreService")
local LeaderboardStore = DataStoreService:GetOrderedDataStore("KillLeaderboard")

local Season1Store = DataStoreService:GetOrderedDataStore("KillLeaderboard", "Season1")
```

## Events

## See also

{% content-ref url="/pages/UhMJ4cZ06n5d2vzza3Pw" %}
[Saving & Loading Data](/manual/script-manual/advanced-gameplay-systems/datastore.md)
{% endcontent-ref %}

{% content-ref url="/pages/faztiZVM1KMYewnGlEy3" %}
[Custom Leaderboard](/manual/script-manual/advanced-gameplay-systems/ordereddatastore.md)
{% endcontent-ref %}
