How do you use UpdateAsync to update bool values within tables that are going to be saved to datastores? My question is how does UpdateAsync work with tables and how does it know which value you want to be updated?
For example:
local data = { car = true, truck = false, van = false }
and after you run UpdateAsync() (changes truck and van to be true)
local data = { car = true, truck = true, van = true }
DataStore:UpdateAsync(key, func)
is how you'd use it. You pass the key as first argument, but instead of the value you want to update with as second argument, it is instead a function that returns what you want to save. If this function returns nil, or doesn't return a value at all, the update is cancelled. Also note that the function cannot yield, so don't call wait()
(or anything else that can yield) in your function!
DataStore:UpdateAsync(key, function(previous) return { car = true, truck = true, van = true } end)
previous
is a parameter for your function that is just the previous value. If there is already data you can do previous.truck = true
, etc