PcoWSkbVqDnWTu_dm2ix
The Developer Hub is now deprecated and information on this page may no longer be accurate. To see our new and improved documentation, please click here. You can read more about the future of documentation here.
Collapse Sidebar

GetDataStore

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 DataStoreOptions/AllScopes|AllScopes. See here for details on scope.

See Also

  • Articles/Data store|Data Stores, an in-depth guide on data structure, management, error handling, etc.

Parameters

Name Type Default Description

Name of the data store.

global

(Optional) A string specifying the scope.

nil

(Optional) A DataStoreOptions instance to enable experimental features and v2 API features.

Returns

Return Type Summary

A GlobalDataStore instance with provided name and optional scope.


Code Samples


Access Non-Scoped Data Store

local DataStoreService = game:GetService("DataStoreService")

local experienceStore = DataStoreService:GetDataStore("PlayerExperience", nil)

Access Scoped Data Store

DataStoreOptions contains an DataStoreOptions/AllScopes|AllScopes property that allows you to return keys from all scopes in a convenient list; you can then use a list item’s DataStoreKey/KeyName|KeyName property for common data store operations like GlobalDataStore/GetAsync|GetAsync() and GlobalDataStore/RemoveAsync|RemoveAsync(). When you use this property, the second parameter of DataStoreService/GetDataStore|GetDataStore() must be an empty string ("").

local DataStoreService = game:GetService("DataStoreService")

local options = Instance.new("DataStoreOptions")
options.AllScopes = true

local experienceStore = DataStoreService:GetDataStore("PlayerExperience", "", options)