Skip to content

Service · inherits Instance

DataStoreService

Official docs ↗

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

About DataStoreService

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(name: string, scope: string = global, options: Instance = nil) → DataStoreCreates a DataStore instance with the provided name and scope.

    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.

  • GetGlobalDataStore() → DataStoreReturns the default data store.

    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.

  • GetOrderedDataStore(name: string, scope: string = global) → OrderedDataStoreGet an OrderedDataStore given a name and optional scope.

    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.

  • GetRequestBudgetForRequestType(requestType: DataStoreRequestType) → intReturns the number of requests that can be made by the given request type.

    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.

  • ListDataStoresAsync(prefix: string, pageSize: int = 0, cursor: string) → DataStoreListingPagesYieldsReturns a DataStoreListingPages object for enumerating through all of the experience's data stores.

    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.

  • SetRateLimitForRequestType(requestType: DataStoreRequestType, baseLimit: int, perPlayerLimit: int) → ()Sets the rate limit for a given request type per minute.

    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]

DataStoreService also has every member of Instance. Deprecated and Roblox-only members are hidden.

Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.