GetDataStore
For thread safety, this property is not safe to read in an unsynchronized thread.
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 |
Returns
| Return Type | Summary |
|---|---|
|
A |
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)