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:
1 | Asset = { |
2 | a = 1 |
3 | b = "string" |
4 | c = true |
5 | } |
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:
1 | DS = game:GetService( "DataStoreService" ) |
2 | dsuser = DS:GetDataStore( "WepDS" ,userkey) |
3 | 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:
01 | local DS = game:GetService( "DataStoreService" ) |
02 | dsuser = DS:GetDataStore( "WepDS" ,userkey) |
03 | dsuser:SetAsync( "a" , 1 ) |
04 | dsuser:SetAsync( "b" , "string" ) |
05 | dsuser:SetAsync( "c" , "true" ) |
06 |
07 | --When you want to change "c" to false |
08 | dsuser:SetAsync( "c" , false ) |
09 |
10 | --reading this data |
11 |
12 | 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