GetAsync
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts.
For thread safety, this property is not safe to read in an unsynchronized thread.
This function returns the latest value of the provided key and a DataStoreKeyInfo instance. If the key does not exist or if the latest version has been marked as deleted, both return values will be nil.
OrderedDataStore does not support versioning and metadata, so DataStoreKeyInfo will always be nil for keys in an OrderedDataStore.
Keys are cached locally for 4 seconds after the first read. A GlobalDataStore/GetAsync call within these 4 seconds returns a value from the cache. Modifications to the key by GlobalDataStore/SetAsync or GlobalDataStore/UpdateAsync apply to the cache immediately and restart the 4 second timer.
DataStore/GetVersionAsync.
See Also
Articles/Data store|Data Stores, an in-depth guide on data structure, management, error handling, etc.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
|
|
The key name for which the value is requested. If |
Returns
| Return Type | Summary |
|---|---|
|
The value of the entry in the data store with the given key and a |
Code Samples
Read Data Store Key/Value
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
local success, currentExperience, keyInfo = pcall(function()
return experienceStore:GetAsync("User_1234")
end)
if success then
print(currentExperience)
print(keyInfo.Version)
print(keyInfo.CreatedTime)
print(keyInfo.UpdatedTime)
print(keyInfo:GetUserIds())
print(keyInfo:GetMetadata())
end