Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it possible to SetAsync on a certain value of a key?

Asked by 7 years ago

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:

1Asset = {
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:

1DS = game:GetService("DataStoreService")
2dsuser = DS:GetDataStore("WepDS",userkey)
3dsuser:setAsync("Asset".c,false) --Yeah that .c wont work i know :P

1 answer

Log in to vote
0
Answered by 7 years ago

You can try using multiple keys so you won't have to use a table:

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

0
Yes, you're right. As for using keys rather than table, I used table because it wanted it to look neat when using the datastore plugin. In actuality, Asset is my sword, var a,b, and c are the sword stats. So if i powerup the sword, c's value would change. Note: WepDS can hold more than 1 similar sword for a player, therefor using 3 keys rather than table would be a whole lot of mess lesliesoon 86 — 7y
0
ah in that case if you want to use a table, you'll just have to save the table with the new value SmugNyan 24 — 7y
0
Yup i guess I"ll have to overwrite the entire thing. Now i see why there aren't any conventional RPG games made in roblox. All of them are very limited :P lesliesoon 86 — 7y
Ad

Answer this question