Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 answer

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

3 comments

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

0

ah in that case if you want to use a table, you'll just have to save the table with the new value

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

This discussion is preserved as it was. New answers, comments, and votes are closed.