Roblox UtilitiesDevlHub Roblox Documentation

Class

DataStore

NotCreatableNotReplicated
Memory category
Instances

A GlobalDataStore that also supports versioning, key metadata, and enumerating keys.

See Data stores for an in-depth guide on data structure, management, error handling, limits, and more.

Methods 5#

GetVersionAsyncRetrieves the specified key version.Yields
GetVersionAtTimeAsyncRetrieves the key version that was current at a given time.Yields
ListKeysAsyncReturns a DataStoreKeyPages object for enumerating through keys of a data store.Yields
ListVersionsAsyncEnumerates all versions of a key.Yields
RemoveVersionAsyncPermanently deletes the specified version of a key.DeprecatedYields

GetVersionAsync(key: string, version: string): Tuple#

Yields

This function retrieves the specified key version as well as a DataStoreKeyInfo instance. A version identifier can be found through DataStore:ListVersionsAsync() or alternatively be the identifier returned by GlobalDataStore:SetAsync().

NameTypeDefaultDescription
keystringKey name for which the version info is requested. If DataStoreOptions.AllScopes was set to true when accessing the data store through DataStoreService:GetDataStore(), this key name must be prepended with the original scope as in "scope/key".
versionstringVersion number of the key for which the version info is requested.
Returns
  • Tuple — The value of the key at the specified version and a DataStoreKeyInfo instance that includes the version number, date and time the version was created, and functions to retrieve UserIds and metadata.

GetVersionAtTimeAsync(key: string, timestamp: int64): Tuple#

Yields

This function retrieves the key version that was current at a given time as well as a DataStoreKeyInfo instance.

NameTypeDefaultDescription
keystringKey name for which the version info is requested. If DataStoreOptions.AllScopes was set to true when accessing the data store through DataStoreService:GetDataStore(), this key name must be prepended with the original scope as in "scope/key".
timestampint64Unix 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
  • Tuple — The value of the key that was current at the specified time and a DataStoreKeyInfo 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(prefix: string, pageSize: int = 0, cursor: string, excludeDeleted: boolean = false): DataStoreKeyPages#

Yields

This function returns a DataStoreKeyPages object for enumerating through keys of a data store. It accepts an optional prefix parameter to only locate keys whose names start with the provided prefix.

If DataStoreOptions.AllScopes was set to true when accessing the data store through DataStoreService:GetDataStore(), keys will be returned with all scopes as prefixes.

NameTypeDefaultDescription
prefixstring(Optional) Prefix to use for locating keys.
pageSizeint0(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.
cursorstring(Optional) Cursor to continue iteration.
excludeDeletedbooleanfalse(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

ListVersionsAsync(key: string, sortDirection: SortDirection = Ascending, minDate: int64 = 0, maxDate: int64 = 0, pageSize: int = 0): DataStoreVersionPages#

Yields

This function enumerates versions of the specified key in either ascending or descending order specified by a SortDirection parameter. It can optionally filter the returned versions by minimum and maximum timestamp.

NameTypeDefaultDescription
keystringKey name for the versions to list. If DataStoreOptions.AllScopes was set to true when accessing the data store through DataStoreService:GetDataStore(), this key name must be prepended with the original scope as in "scope/key".
sortDirectionSortDirectionAscending(Optional) Enum specifying ascending or descending sort order.
minDateint640(Optional) Unix timestamp in milliseconds after which the versions should be listed.
maxDateint640(Optional) Unix timestamp in milliseconds up to which the versions should be listed.
pageSizeint0(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

RemoveVersionAsync(key: string, version: string): ()#

YieldsDeprecatedDeprecated

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

This function permanently deletes the specified version of a key. Version identifiers can be found through DataStore:ListVersionsAsync().

Unlike GlobalDataStore:RemoveAsync(), this function does not create a new "tombstone" version and the removed value cannot be retrieved later.

NameTypeDefaultDescription
keystringKey name for which a version is to be removed. If DataStoreOptions.AllScopes was set to true when accessing the data store through DataStoreService:GetDataStore(), this key name must be prepended with the original scope as in "scope/key".
versionstringVersion number of the key to remove.
Returns
  • ()

Inherited members#

Inherited from GlobalDataStore 7
Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed