Roblox UtilitiesDevlHub Roblox Documentation

Class

DataStoreService

NotCreatableServiceNotReplicated
Inherits
Instance › Object
Memory category
Instances

A game service that gives access to persistent data storage across places in a game.

DataStoreService exposes methods for getting GlobalDataStore and OrderedDataStore objects. Data stores can only be accessed by game servers, so you can only use DataStoreService within a Script or a ModuleScript that is used by a Script.

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

Methods 6#

GetDataStoreCreates a DataStore instance with the provided name and scope.
GetGlobalDataStoreReturns the default data store.
GetOrderedDataStoreGet an OrderedDataStore given a name and optional scope.
GetRequestBudgetForRequestTypeReturns the number of requests that can be made by the given request type.
ListDataStoresAsyncReturns a DataStoreListingPages object for enumerating through all of the experience's data stores.Yields
SetRateLimitForRequestTypeSets the rate limit for a given request type per minute.

GetDataStore(name: string, scope: string = global, options: Instance = nil): DataStore#

This function creates a DataStore instance with the provided name and scope. Subsequent calls to this method with the same name/scope will return the same object.

Using the scope parameter will restrict operations to that scope by automatically prepending the scope to keys in all operations done on the data store. This function also accepts an optional DataStoreOptions instance which includes options for enabling AllScopes. See Versioning, listing, and caching for details on scope.

NameTypeDefaultDescription
namestringName of the data store.
scopestringglobal(Optional) A string specifying the scope.
optionsInstancenil(Optional) A DataStoreOptions instance to enable experimental features and v2 API features.
Returns

GetGlobalDataStore(): DataStore#

This function returns the default GlobalDataStore. If you want to access a specific named data store instead, you should use the GetDataStore() function.

Note that the DataStore returned by this function always uses the scope u. See Data stores for details on scope.

Returns

GetOrderedDataStore(name: string, scope: string = global): OrderedDataStore#

This method returns an OrderedDataStore, similar to the way GetDataStore() does with GlobalDataStores. Subsequent calls to this method with the same name/scope will return the same object.

NameTypeDefaultDescription
namestringName of the ordered data store.
scopestringglobal(Optional) A string specifying the scope. Default is "global".
Returns

GetRequestBudgetForRequestType(requestType: DataStoreRequestType): int#

This function returns the number of data store requests that the current place can make based on the given DataStoreRequestType. Any requests made that exceed this budget are subject to throttling. Monitoring and adjusting the frequency of data store requests using this function is recommended.

NameTypeDefaultDescription
requestTypeDataStoreRequestTypeThe DataStoreRequestType to check the budget for.
Returns
  • int — The number of data store requests that can currently be made for the specified request type.

ListDataStoresAsync(prefix: string, pageSize: int = 0, cursor: string): DataStoreListingPages#

Yields

Returns a DataStoreListingPages object for enumerating through all of the experience's data stores. It accepts an optional prefix parameter to only locate data stores whose names start with the provided prefix.

Only data stores containing at least one object will be listed via this function.

NameTypeDefaultDescription
prefixstring(Optional) Prefix to enumerate data stores that start with the given prefix.
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 32 items per page.
cursorstring(Optional) Cursor to continue iteration.
Returns

SetRateLimitForRequestType(requestType: DataStoreRequestType, baseLimit: int, perPlayerLimit: int): ()#

Sets the per-server rate limit (requests per minute) for a given Data Store request type. The configured limit overrides the default rate limit for that request type on the current server. The rate limit is calculated as rateLimit = baseLimit + (perPlayerLimit * numPlayers), where numPlayers is the current number of active players on the server. DataStoreRequestType.OnUpdate and DataStoreRequestType.UpdateAsync cannot be configured with this function. Calling this API with those request types will result in an error.

You should call this API once per request type during server initialization. We don't recommend calling this API during active experience logic. If called multiple times, the new limit definitions will immediately overwrite the previous ones.

The baseLimit and perPlayerLimit have different constraints depending on the request type. See the table below for more information.

Constraints by Request Type#
Request Type baseLimit constraints perPlayerLimit constraints
GetAsync [0, 60] [0, 40]
SetIncrementAsync [0, 60] [0, 40]
UpdateAsync N/A N/A
GetSortedAsync [0, 5] [0, 2]
SetIncrementSortedAsync [0, 30] [0, 5]
OnUpdate N/A N/A
ListAsync [0, 5] [0, 2]
GetVersionAsync [0, 5] [0, 2]
RemoveVersionAsync [0, 5] [0, 2]
StandardRead [0, 10000] [0, 200]
StandardWrite [0, 10000] [0, 200]
StandardList [0, 10000] [0, 200]
StandardRemove [0, 10000] [0, 200]
OrderedRead [0, 10000] [0, 200]
OrderedWrite [0, 10000] [0, 200]
OrderedList [0, 10000] [0, 200]
OrderedRemove [0, 10000] [0, 200]
NameTypeDefaultDescription
requestTypeDataStoreRequestTypeThe DataStoreRequestType to configure the rate limit for.
baseLimitintThe base number of requests allowed per minute regardless of player count.
perPlayerLimitintThe additional number of requests per minute granted for each connected player.
Returns
  • ()

Inherited members#

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

ClassName, className

Events (1)

Changed