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

How would you save a table in DataStore?

Asked by 8 years ago

I'm trying to make it so the player's inventory saves (Not the player's backpack and starterpack, just a GUI inventory). The ROBLOX Wiki lacks examples, and can't find any understandable answers

1 answer

Log in to vote
2
Answered by 8 years ago
Edited 7 years ago

SetAsync / UpdateAsync

You can save a table to data store the same way you can save any other valid data type to data store; by passing it as the second argument to SetAsync or as the return value of UpdateAsync. The only exception is the table must be in either array or dictionary format, not a mixture of both. Saving a mixture of both will most likely yield losing the array part. Example:

-- Saving an array
DataStore:UpdateAsync("Test", {1,2,3})

-- Saving a dictionary
DataStore:SetAsync("Test", {a=1, b=2, c=3})

Data Limit

It's also important you know that tables are saved to JSON, and therefore the string length of the encoded JSON table is limited to how much memory can be stored at once (this is approximately 2^18 string characters). Going over this limit will cancel your save request.


Hope this helped, if you have any questions, just let me know.

0
Oh, so datastore only saves values, not instances? supermarioworld323 45 — 8y
0
Correct. If you wanted to save an instance, it'd have to be serialized, saved and decoded upon loading it. ScriptGuider 5640 — 8y
0
Ok thank you supermarioworld323 45 — 8y
Ad

Answer this question