DataStore
Show Deprecated
See Data Stores.
Summary
Methods
Retrieves the specified key version.
Retrieves the key version that was current at a given time.
- ListKeysAsync(prefix : string,pageSize : number,cursor : string,excludeDeleted : boolean):DataStoreKeyPages
Returns a DataStoreKeyPages object for enumerating through keys of a data store.
- ListVersionsAsync(key : string,sortDirection : Enum.SortDirection,minDate : number,maxDate : number,pageSize : number):DataStoreVersionPages
Enumerates all versions of a key.
Permanently deletes the specified version of a key.
Methods
Returns the value of a key in a specified data store and a DataStoreKeyInfo instance.
- IncrementAsync(key : string,delta : number,userIds : Array,options : DataStoreIncrementOptions):Variant
Increments the value of a key by the provided amount (both must be integers).
Removes the specified key while also retaining an accessible version.
Sets the value of the data store for the given key.
Updates a key's value with a new value from the specified callback function.
Properties
Methods
GetVersionAtTimeAsync
Parameters
Returns
Code Samples
Retrieving DataStore Versions by Time
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("DataStore")
local key = "key-123"
function setData(data)
local success, result = pcall(function()
dataStore:SetAsync(key, data)
end)
if not success then
warn(result)
end
end
function getVersionAtTime(timestamp)
local success, result, keyInfo = pcall(function()
return dataStore:GetVersionAtTimeAsync(key, timestamp.UnixTimestampMillis)
end)
if success then
if result == nil then
print("No version found at time")
else
print(result, keyInfo.Version)
end
else
warn(result)
end
end
-- Previously ran at 2024/12/02 6:00 UTC
setData("version 1")
-- Previously ran at 2024/12/02 9:00 UTC
setData("version 2")
-- Prints "No version found at time"
local time1 = DateTime.fromUniversalTime(2024, 12, 02, 05, 00)
getVersionAtTime(time1)
-- Prints "version 1 <version>"
local time2 = DateTime.fromUniversalTime(2024, 12, 02, 07, 00)
getVersionAtTime(time2)
-- Prints "version 2 <version>"
local time3 = DateTime.fromUniversalTime(2024, 12, 02, 10, 00)
getVersionAtTime(time3)
ListKeysAsync
Parameters
Default Value: 0
Default Value: false
Returns
ListVersionsAsync
Parameters
Default Value: "Ascending"
Default Value: 0
Default Value: 0
Default Value: 0
Returns
Code Samples
Retrieving DataStore Versions With A Date Filter
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
local time = DateTime.fromUniversalTime(2020, 10, 09, 01, 42)
local listSuccess, pages = pcall(function()
return experienceStore:ListVersionsAsync("User_1234", nil, time.UnixTimestampMillis)
end)
if listSuccess then
local items = pages:GetCurrentPage()
for key, info in pairs(items) do
print("Key:", key, "; Version:", info.Version, "; Created:", info.CreatedTime, "; Deleted:", info.IsDeleted)
end
end
Properties inherited from GlobalDataStore