How would I save a table using SetAsync?
COMMUNITY QUESTION
How do I save a table to Data Store?
3 answers
You can use the http service. The script may has some error:
local table = {a = "0",b = "0"} -- The main table
local ds = game:GetService("DataStoreService") -- datastore service
local hs = game.HttpService -- the http service
local nds = ds:GetDataStore("test")
local value = hs:JSONDecode(nds)
if value == nil then -- if it the first time you start the game then you start with the main table
value = table
else
value.a = value.a + 1 --we want to add 1 to a every time
value.b = value.b + 2 --we want to add 2 to b every time
end
local encode = hs:JSONEncode(value)
hs:SetAsync("test",encode) -- may be it (encode,"test")
http://www.roblox.com/Forum/ShowPost.aspx?PostID=128157478 < That should help you.
1 comment
0
The Roblox forum is no longer active
You would save it as you would another type of data, but do remember the 65536 character limitation and that it saves the table encoded in JSON, to get the length of the encoded table length, doprint(string.length(game:GetService('HttpService'):JSONEncode(table)))
Example:
game:GetService('DataStoreService'):GetDataStore('AName'):SetAsync('table',{'a','b','c'})
local t = game:GetService('DataStoreService'):GetDataStore('AName'):GetAsync('table')
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Go to roblox wiki.
I don't know what the people above me are talking about with HTTP Service and stuff. Just save it like anything else. http://prntscr.com/ma4rd3