GlobalDataStore

GlobalDataStore : Instance

Properties

Methods

GetAsync

Retrieves the latest value of a specified key along with metadata, such as version information.

Parameters

string InKey

DataStoreGetOptions InOptions

Return

Tuple

Code Samples

local DataStoreService = game:GetService("DataStoreService") 
local GoldStore = DataStoreService:GetDataStore("PlayerGold") 

local success, errorMessageOrLoadValue = pcall(function()
    return GoldStore:GetAsync(player.UserId)
end)

IncrementAsync

Increments the numeric value of a key by a specified amount.

Parameters

string InKey

number InDelta

array InUserIds

DataStoreIncrementOptions InOptions

Return

Value

Code Samples

local DataStoreService = game:GetService("DataStoreService") 
local GoldStore = DataStoreService:GetDataStore("PlayerGold") 

local success, errorMessageOrLoadValue = pcall(function()
    return GoldStore:IncrementAsync(player.UserId, 1)
end)

RemoveAsync

Deletes a key from the data store while retaining an accessible version history.

Parameters

string InKey

Return

Tuple

Code Samples

local DataStoreService = game:GetService("DataStoreService") 
local GoldStore = DataStoreService:GetDataStore("PlayerGold") 

local success, errorMessageOrLoadValue = pcall(function()
    return GoldStore:RemoveAsync(player.UserId)
end)

SetAsync

Sets or updates the value for a given key, creating a new version each time it is called.

Parameters

string InKey

Value InValue

Value InUserIds

DataStoreSetOptions InOptions

Return

Value

Code Samples

local DataStoreService = game:GetService("DataStoreService") 
local GoldStore = DataStoreService:GetDataStore("PlayerGold") 

local success, errorMessageOrLoadValue = pcall(function()
    GoldStore:SetAsync(player.UserId, 100) 
end)

UpdateAsync

Safely updates a key's value by reading its current state before applying changes, useful for handling concurrent modifications.

Parameters

string InKey

Value InTransformFunction

Return

Tuple

Code Samples

local DataStoreService = game:GetService("DataStoreService") 
local GoldStore = DataStoreService:GetDataStore("PlayerGold") 

local success, errorMessageOrLoadValue, keyInfo = pcall(function()
    return GoldStore:UpdateAsync(player.UserId, function(currentGold, keyInfo)
        local newGold = (currentGold or 0) + 10		
        return { newGold, keyInfo:GetUserIds(), keyInfo:GetMetadata() }
    end)
end)

Events

Last updated