Hi guys, I'm playing around with weapon pickups & saving/loading assets from the data store. lets say I have a key named "Asset" inside a datastore which is a table with lets say 3 variables so the key's structure will be something like:
Asset = { a = 1 b = "string" c = true }
If I only wanted to edit "c = false", how do i go about doing that? The only solution i know of is to grab the entire table, store it inside a variable, then edit c's value inside that variable, and upload the entire table from that variable back into the server. But just to update a single variable's value by doing this seems really inefficient. Is there a better way?
I know this wont work but is there something like:
DS = game:GetService("DataStoreService") dsuser = DS:GetDataStore("WepDS",userkey) dsuser:setAsync("Asset".c,false) --Yeah that .c wont work i know :P
You can try using multiple keys so you won't have to use a table:
local DS = game:GetService("DataStoreService") dsuser = DS:GetDataStore("WepDS",userkey) dsuser:SetAsync("a", 1) dsuser:SetAsync("b", "string") dsuser:SetAsync("c", "true") --When you want to change "c" to false dsuser:SetAsync("c", false) --reading this data dsuser:GetAsync("c")
To make this easier to understand, you have your datastore "WepDS" in a variable thing, then you set the keys with :SetAsync(key, value). Next you can overwrite the data with dsuser:SetAsync(key, new value). To get the new value just do :GetAsync(key) and it'll give the new value.
note: This is all from memory so correct me if I'm wrong