# DataStore

Roblox Engine API class from Roblox Studio 0.744.0.7441077 (version-7aaa6838d36c4448).

- Inherits from, nearest first: [GlobalDataStore](https://rapi.sleaze.dev/classes/GlobalDataStore.md), [Instance](https://rapi.sleaze.dev/classes/Instance.md), [Object](https://rapi.sleaze.dev/classes/Object.md)
- Tags: Not creatable, Not replicated
- Memory category: Instances
- HTML page: https://rapi.sleaze.dev/classes/DataStore/
- Roblox documentation: https://create.roblox.com/docs/reference/engine/classes/DataStore

A [`GlobalDataStore`](https://rapi.sleaze.dev/classes/GlobalDataStore.md) that also supports versioning, key metadata, and enumerating keys.

## Methods

### GetVersionAsync

```luau
DataStore:GetVersionAsync(key: string, version: string): ...any
```

- Tags: Yields, Capabilities: DataStore

Retrieves the specified key version.

Parameters:

- `key`: Key name for which the version info is requested. If [`DataStoreOptions.AllScopes`](https://rapi.sleaze.dev/classes/DataStoreOptions.md) was set to true when accessing the data store through [`DataStoreService:GetDataStore()`](https://rapi.sleaze.dev/classes/DataStoreService.md), this key name must be prepended with the original scope as in "scope/key".
- `version`: Version number of the key for which the version info is requested.

Returns: The value of the key at the specified version and a [`DataStoreKeyInfo`](https://rapi.sleaze.dev/classes/DataStoreKeyInfo.md) instance that includes the version number, date and time the version was created, and functions to retrieve `UserIds` and metadata.

### GetVersionAtTimeAsync

```luau
DataStore:GetVersionAtTimeAsync(key: string, timestamp: number): ...any
```

- Tags: Yields, Capabilities: DataStore

Retrieves the key version that was current at a given time.

Parameters:

- `key`: Key name for which the version info is requested. If [`DataStoreOptions.AllScopes`](https://rapi.sleaze.dev/classes/DataStoreOptions.md) was set to true when accessing the data store through [`DataStoreService:GetDataStore()`](https://rapi.sleaze.dev/classes/DataStoreService.md), this key name must be prepended with the original scope as in "scope/key".
- `timestamp`: Unix timestamp in milliseconds for which the requested version was current. Must be greater than zero. Must not be more than ten minutes in the future.

Returns: The value of the key that was current at the specified time and a [`DataStoreKeyInfo`](https://rapi.sleaze.dev/classes/DataStoreKeyInfo.md) instance that includes the version number, date and time the version was created, and functions to retrieve `UserIds` and metadata. `nil` if no available version was current at the requested time.

### ListKeysAsync

```luau
DataStore:ListKeysAsync(prefix: string? = "", pageSize: number? = 0, cursor: string? = "", excludeDeleted: boolean? = false): DataStoreKeyPages
```

- Tags: Yields, Capabilities: DataStore

Returns a [`DataStoreKeyPages`](https://rapi.sleaze.dev/classes/DataStoreKeyPages.md) object for enumerating through keys of a data store.

Parameters:

- `prefix`: **(Optional)** Prefix to use for locating keys.
- `pageSize`: **(Optional)** Number of items to be returned in each page. If no value is given, the engine sends a default value of 0 to the data store web service, which in turn defaults to 50 items per page.
- `cursor`: **(Optional)** Cursor to continue iteration.
- `excludeDeleted`: **(Optional)** Exclude deleted keys from being returned. When enabled ListKeys will check up to 512 keys. If all checked keys are deleted then it will return an empty list with a cursor to continue iteration.

Returns: A [`DataStoreKeyPages`](https://rapi.sleaze.dev/classes/DataStoreKeyPages.md) instance that enumerates the keys as [`DataStoreKey`](https://rapi.sleaze.dev/classes/DataStoreKey.md) instances.

### ListVersionsAsync

```luau
DataStore:ListVersionsAsync(key: string, sortDirection: Enum.SortDirection? = Enum.SortDirection.Ascending, minDate: number? = 0, maxDate: number? = 0, pageSize: number? = 0): DataStoreVersionPages
```

- Tags: Yields, Capabilities: DataStore

Enumerates all versions of a key.

Parameters:

- `key`: Key name for the versions to list. If [`DataStoreOptions.AllScopes`](https://rapi.sleaze.dev/classes/DataStoreOptions.md) was set to true when accessing the data store through [`DataStoreService:GetDataStore()`](https://rapi.sleaze.dev/classes/DataStoreService.md), this key name must be prepended with the original scope as in "scope/key".
- `sortDirection`: **(Optional)** Enum specifying ascending or descending sort order.
- `minDate`: **(Optional)** Unix timestamp in milliseconds after which the versions should be listed.
- `maxDate`: **(Optional)** Unix timestamp in milliseconds up to which the versions should be listed.
- `pageSize`: **(Optional)** Number of items to be returned in each page. If no value is given, the engine sends a default value of 0 to the data store web service, which in turn defaults to 1024 items per page.

Returns: A [`DataStoreVersionPages`](https://rapi.sleaze.dev/classes/DataStoreVersionPages.md) instance that enumerates all the versions of the key as [`DataStoreObjectVersionInfo`](https://rapi.sleaze.dev/classes/DataStoreObjectVersionInfo.md) instances.

### RemoveVersionAsync

```luau
DataStore:RemoveVersionAsync(key: string, version: string)
```

- Tags: Deprecated, Yields, Capabilities: DataStore

**Deprecated:** This method is deprecated. Do not use it for new work.

Permanently deletes the specified version of a key.

Parameters:

- `key`: Key name for which a version is to be removed. If [`DataStoreOptions.AllScopes`](https://rapi.sleaze.dev/classes/DataStoreOptions.md) was set to true when accessing the data store through [`DataStoreService:GetDataStore()`](https://rapi.sleaze.dev/classes/DataStoreService.md), this key name must be prepended with the original scope as in "scope/key".
- `version`: Version number of the key to remove.

## Inherited members

- From [GlobalDataStore](https://rapi.sleaze.dev/classes/GlobalDataStore.md): `BatchGetAsync`, `GetAsync`, `IncrementAsync`, `RemoveAsync`, `SetAsync`, `UpdateAsync`, `OnUpdate`
- From [Instance](https://rapi.sleaze.dev/classes/Instance.md): `Archivable`, `archivable`, `Attributes`, `AttributesReplicate`, `AttributesSerialize`, `HistoryId`, `Name`, `Parent`, `PredictionMode`, `PropertyStatusStudio`, `RobloxLocked`, `SerializedOverrides`, `SourceAssetId`, `Tags`, `UniqueId`, `numExpectedDirectChildren`, `DataCost`, `Capabilities`, `DefinesCapabilities`, `IsInSandbox`, `Sandboxed`, `AddTag`, `ClearAllChildren`, `Clone`, `Destroy`, `FindFirstAncestor`, `FindFirstAncestorOfClass`, `FindFirstAncestorWhichIsA`, `FindFirstChild`, `FindFirstChildOfClass`, `FindFirstChildWhichIsA`, `FindFirstDescendant`, `GetActor`, `GetAttribute`, `GetAttributeChangedSignal`, `GetAttributes`, `GetChildren`, `GetDebugId`, `GetDescendants`, `GetFullName`, `GetStyled`, `GetStyledPropertyChangedSignal`, `GetTags`, `HasTag`, `IsAncestorOf`, `IsDescendantOf`, `IsPropertyModified`, `QueryDescendants`, `RemoveTag`, `ResetPropertyToDefault`, `SetAttribute`, `WaitForChild`, `Remove`, `children`, `clone`, `destroy`, `findFirstChild`, `getChildren`, `isDescendantOf`, `remove`, `AncestryChanged`, `AttributeChanged`, `ChildAdded`, `ChildRemoved`, `DescendantAdded`, `DescendantRemoving`, `Destroying`, `StyledPropertiesChanged`, `childAdded`
- From [Object](https://rapi.sleaze.dev/classes/Object.md): `ClassName`, `className`, `GetPropertyChangedSignal`, `IsA`, `isA`, `Changed`
