Lets say that I have in a data store a key and a value. Lets say that the key is “x” and the value is equal to 7 for example. If I later on ran a :SetAsync() command to set “x” to 8, will it overwrite the original x = 7 or would it simply add on to what is inside the data store and give me a random value out of the two when calling :GetAsync()? I am aware that it is bad practice to overwrite instead of :UpdateAsync(). However, is there potential for the DataStoreService functioning in a game with how I am trying to use it?
Think of a datastore as a dictionary (which it basically is). To increment the value held by a dictionary key, you have to do something along the lines of “dictionary[“key”] = dictionary[“key”] + number”. SetAsync is the equivalent of just setting the value of that key, “dictionary[“key”] = value”.
yup i wrap it on a pcall, sorry i forgot to write it lol
heres my script
local success, err = pcall(function()
local Data = {}
Data = BackPack:GetAsync(player.UserId)
Data[ItemName] = 1
BackPack:SetAsync(player.UserId, Data)
Data = nil
end)
if err then
warn(err)
--gui that warns player that data is not saved
--trying to save it again
end