IncrementAsync
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 increments the value of a key by the provided amount (both must be integers).
OrderedDataStore does not support versioning, so calling this method on an OrderedDataStore key will overwrite the current value with the incremented value and make previous versions inaccessible.
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 value should be updated. If |
||
|
1
|
Amount to increment the current value by. |
||
|
{}
|
(Optional) A table of |
||
|
nil
|
(Optional) |
Returns
| Return Type | Summary |
|---|---|
|
The updated value of the entry in the data store with the given key. |
Code Samples
Increment Data Store Key/Value
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
local incrementOptions = Instance.new("DataStoreIncrementOptions")
incrementOptions:SetMetadata({["ExperienceElement"] = "Fire"})
local success, newExperience, keyInfo = pcall(function()
return experienceStore:IncrementAsync("User_1234", 10, {1234}, incrementOptions)
end)
if success then
print(newExperience)
print(keyInfo.Version)
print(keyInfo.CreatedTime)
print(keyInfo.UpdatedTime)
print(keyInfo:GetUserIds())
print(keyInfo:GetMetadata())
end