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

How do I save a table to Data Store?

Asked by 9 years ago

How would I save a table using SetAsync?

1
Go to roblox wiki. EzraNehemiah_TF2 3552 — 9y
0
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 GFink 0 — 5y

3 answers

Log in to vote
1
Answered by 6 years ago

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")
Ad
Log in to vote
0
Answered by 9 years ago

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')

Log in to vote
0
Answered by
Aespect 25
9 years ago

http://www.roblox.com/Forum/ShowPost.aspx?PostID=128157478 < That should help you.

0
The Roblox forum is no longer active Tymberlejk 143 — 5y

Answer this question