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 10 years ago

How would I save a table using SetAsync?

1
Go to roblox wiki. EzraNehemiah_TF2 3552 — 10y
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 — 6y

3 answers

Log in to vote
1
Answered by 7 years ago

You can use the http service. The script may has some error:

01local table = {a = "0",b = "0"} -- The main table
02local ds = game:GetService("DataStoreService") -- datastore service
03local hs = game.HttpService -- the http service
04local nds = ds:GetDataStore("test")
05local value = hs:JSONDecode(nds)
06if value == nil then -- if it the first time you start the game then you start with the main table
07    value = table
08else
09    value.a = value.a + 1 --we want to add 1 to a every time
10    value.b = value.b + 2 --we want to add 2 to b every time
11end
12local encode = hs:JSONEncode(value)
13hs:SetAsync("test",encode) -- may be it (encode,"test")
Ad
Log in to vote
0
Answered by 10 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:

1game:GetService('DataStoreService'):GetDataStore('AName'):SetAsync('table',{'a','b','c'})
2local t = game:GetService('DataStoreService'):GetDataStore('AName'):GetAsync('table')
Log in to vote
0
Answered by
Aespect 25
10 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 — 6y

Answer this question