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

Is it possible to save tables to the Data Store?

If I wanted to save a table that listed all the items a player has in game to the data store, could I? Is it even possible?

3 answers

✓ Accepted answer

Yep. Data Store is designed to handle:

  • numbers
  • strings
  • tables
  • booleans

You can just enter a table in there!

So, side note: Data Persistence allowed to save instances: Data Store cannot (directly) do this. Data Store can save tables: Data Persistence cannot directly do this.

6 comments

0

Also saves Boolean. Side note: Tables must be under 64,000 bytes from what I hear.

0

True. The string though, not the table. You need to convert the table to JSON (a string) and then count it. I'm not sure if it's 64k or 2^16 though.

0

So, how exactly would I save a players inventory into a tabke?

0

Want me to make my tool saving script using DataStoreService public? It works perfectly. :P

0

DataPersistence is deprecated, isn't it?

0

I'm pretty sure it is since DataCost is deprecated property of all things.

Yes you can the script may contain 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")

" Introduction

ROBLOX is introducing a new API for storing data called Data Stores which is more powerful and robust than the old Data Persistence system. With Data Stores you can store arbitrary data which persists even when games are not running and can be accessed by all instances of a place in your game universe. You probably have used Data persistence. If you haven't, it's strongly suggested to learn how to use the Data Stores instead of the old Data Persistence. Here's a small overview on advantages over Data Persistence. For the disadvantages, see the limitations section. Data Stores have virtually no data limit. Data Persistance has a limit of 45000 data units per player. Data Stores are accessible from any place at any time in the same universe. If a call from the Data Store API returns, the data is confirmed to be saved. So, not data loss when a server crashes. Saves arbitrary lua tables, besides strings, booleans and numbers. Instances cannot be saved direcly though. We can test data stores in a local test server. If you are going to intensively use Data Stores, make sure that you have read the the limitations section too, to prevent frustrations later on. "

This is directly from Roblox Wiki -> http://wiki.roblox.com/index.php?title=Data_store

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