Hi, i am unsure if it is possible to use the updateasync API in Datastore with Lua Tables in order to save data. In this scenario, i created a textlabel which represent the value of coins which the player have, and also a intvalue inside it, however i would like to use updateasync to save multiple values in a table instead of SetAsync to ensure security. If so, how would i called the key which is inside the table? Thanks.
local datastore = game:GetService("DataStoreService"):GetDataStore("LuaTestData")
game.Players.PlayerAdded:connect(function(plr)
local screen = game.Lighting.ScreenGui:clone()
screen.Parent = plr.PlayerGui
local bitstat = screen.Bitstat
local bitvalue = bitstat.Bitvalue
local userkey = "User-" .. plr.UserId
local finduser = datastore:GetAsync(userkey)
if finduser then
local savevalue = {finduser + 20,0}
datastore:SetAsync(userkey,savevalue)
bitvalue.Value = finduser[1]
print("success1")
else
datastore:UpdateAsync(userkey, function(oldvalue)
local newvalue = oldvalue or 0
newvalue = newvalue + 20
return newvalue
end)
bitvalue.Value = finduser[1]
print("success2")
end
game.Players.PlayerRemoving:connect(function(plr)
local userkey = "User-" .. plr.UserId
datastore:UpdateAsync(userkey, function(savevalue)
local newvalue = savevalue
return newvalue
end)
end)

3 comments
You're doing a lot of mixing of syntax for numbers with syntax for tables here, which type of value is finduser supposed to be?
Sorry if i am unclear on this question, but i am currently using SetAsync to save the lua table however i would like to use UpdateASync to save the data inside the table
I am also using a IntValue inside the textlabel which update the textlabel continuously