GetVersionAsync
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 retrieves the specified key version as well as a DataStoreKeyInfo
instance. A version identifier can be found through DataStore/ListVersionsAsync
or alternatively be the identifier returned by GlobalDataStore/SetAsync
.
See Also
Articles/Data store|Data Stores
, an in-depth guide on data structure, management, error handling, etc.
Parameters
Name | Type | Default | Description |
---|---|---|---|
|
Key name for which the version info is requested. If |
||
|
Version number of the key for which the version info is requested |
Returns
Return Type | Summary |
---|---|
The value of the key at the specified version and a |
Code Samples
Restore Closest Key Version
local DataStoreService = game:GetService("DataStoreService") local experienceStore = DataStoreService:GetDataStore("PlayerExperience") local DATA_STORE_KEY = "User_1234" local maxDate = DateTime.fromUniversalTime(year=2020, month=10, day=09, hour=01, min=42) -- Get the version closest to the given time local listSuccess, pages = pcall(function() return experienceStore:ListVersionsAsync(DATA_STORE_KEY, Enum.SortDirection.Descending, nil, maxDate.UnixTimestampMillis) end) if listSuccess then local items = pages:GetCurrentPage() if table.getn(items) > 0 then -- Read the closest version local closestEntry = items[1] local success, value, info = pcall(function() return experienceStore:GetVersionAsync(DATA_STORE_KEY, closestEntry.Version) end) -- Restore current value by overwriting with the closest version if success then local setOptions = Instance.new("DataStoreSetOptions") setOptions:SetMetadata(info:GetMetadata()) experienceStore:SetAsync(DATA_STORE_KEY, value, nil, setOptions) end else -- No entries found end end