Class
DataStoreService
NotCreatableServiceNotReplicated
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#
| GetDataStore | Creates a DataStore instance with the provided name and scope. |
| GetGlobalDataStore | Returns the default data store. |
| GetOrderedDataStore | Get an OrderedDataStore given a name and optional scope. |
| GetRequestBudgetForRequestType | Returns the number of requests that can be made by the given request type. |
| ListDataStoresAsync | Returns a DataStoreListingPages object for enumerating through all
of the experience's data stores.Yields |
| SetRateLimitForRequestType | Sets 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.
| Name | Type | Default | Description |
|---|---|---|---|
name | string | Name of the data store. | |
scope | string | global | (Optional) A string specifying the scope. |
options | Instance | nil | (Optional) A DataStoreOptions instance to enable
experimental features and v2 API features. |
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
DataStore— The defaultGlobalDataStoreinstance.
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.
| Name | Type | Default | Description |
|---|---|---|---|
name | string | Name of the ordered data store. | |
scope | string | global | (Optional) A string specifying the scope. Default is "global". |
Returns
OrderedDataStore— AnOrderedDataStoreinstance with the provided name and scope.
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.
| Name | Type | Default | Description |
|---|---|---|---|
requestType | DataStoreRequestType | The 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.
| Name | Type | Default | Description |
|---|---|---|---|
prefix | string | (Optional) Prefix to enumerate data stores that start with the given prefix. | |
pageSize | int | 0 | (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. |
cursor | string | (Optional) Cursor to continue iteration. |
Returns
DataStoreListingPages—DataStoreListingPagesinstance containingDataStoreInfoinstances that provide details such as name, creation time, and time last updated.
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] |
| Name | Type | Default | Description |
|---|---|---|---|
requestType | DataStoreRequestType | The DataStoreRequestType to configure the rate limit for. | |
baseLimit | int | The base number of requests allowed per minute regardless of player count. | |
perPlayerLimit | int | The additional number of requests per minute granted for each connected player. |
Returns
()
Inherited members#
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild