DataStoreKeyInfo class provides detailed information about a specific version of a key in a data store. This class is particularly useful for managing and retrieving metadata associated with different versions of data stored in data stores.
Description
DataStoreKeyInfo class is typically returned as part of operations that involve accessing specific versions of keys, such as when using GlobalDataStore:GetAsync. It helps developers manage data versions effectively by providing essential metadata and tracking information.
Properties
CreatedTime
number
Indicates when the data store was created.
Code Samples
local DataStoreService = game:GetService("DataStoreService")
local GoldStore = DataStoreService:GetDataStore("PlayerGold")
local success, errorMessageOrLoadValue, keyInfo = pcall(function()
return GoldStore:GetAsync(player.UserId)
end)
if not success then
print("errorMessage : ", errorMessageOrLoadValue)
else
local loadValue = errorMessageOrLoadValue
local createdTime = keyInfo.CreatedTime
local version = keyInfo.Version
local updatedTime = keyInfo.UpdatedTime
end
Version
string
Represents the version identifier of the key in the data store. Each version of a key has a unique identifier that allows developers to track or retrieve specific versions of the key.
Code Samples
local DataStoreService = game:GetService("DataStoreService")
local GoldStore = DataStoreService:GetDataStore("PlayerGold")
local success, errorMessageOrLoadValue, keyInfo = pcall(function()
return GoldStore:GetAsync(player.UserId)
end)
if not success then
print("errorMessage : ", errorMessageOrLoadValue)
else
local loadValue = errorMessageOrLoadValue
local createdTime = keyInfo.CreatedTime
local version = keyInfo.Version
local updatedTime = keyInfo.UpdatedTime
end
UpdatedTime
number
Indicates the last time the data store was updated in milliseconds since epoch.
Code Samples
local DataStoreService = game:GetService("DataStoreService")
local GoldStore = DataStoreService:GetDataStore("PlayerGold")
local success, errorMessageOrLoadValue, keyInfo = pcall(function()
return GoldStore:GetAsync(player.UserId)
end)
if not success then
print("errorMessage : ", errorMessageOrLoadValue)
else
local loadValue = errorMessageOrLoadValue
local createdTime = keyInfo.CreatedTime
local version = keyInfo.Version
local updatedTime = keyInfo.UpdatedTime
end
Methods
GetMetaData
The DataStoreKeyInfo:GetMetadata function retrieves the user-defined metadata associated with the latest version of a key in the data store, which was set using DataStoreSetOptions:SetMetadata.
Parameters
Return
Value
Code Samples
local DataStoreService = game:GetService("DataStoreService")
local GoldStore = DataStoreService:GetDataStore("PlayerGold")
local success, errorMessageOrLoadValue, keyInfo = pcall(function()
return GoldStore:GetAsync(player.UserId)
end)
if not success then
print("errorMessage : ", errorMessageOrLoadValue)
else
local loadValue = errorMessageOrLoadValue
local userIds = keyInfo:GetUserIds()
local metadata = keyInfo:GetMetadata()
end
GetUserIds
Retrieves a list of user IDs associated with the key in a data store. This enables developers to track user-specific interactions or ownership related to specific data entries.
Parameters
Return
array
Code Samples
local DataStoreService = game:GetService("DataStoreService")
local GoldStore = DataStoreService:GetDataStore("PlayerGold")
local success, errorMessageOrLoadValue, keyInfo = pcall(function()
return GoldStore:GetAsync(player.UserId)
end)
if not success then
print("errorMessage : ", errorMessageOrLoadValue)
else
local loadValue = errorMessageOrLoadValue
local userIds = keyInfo:GetUserIds()
local metadata = keyInfo:GetMetadata()
end