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

How do you do DataStore in a table?

Is there a way to DataStore inside of a table?

4 comments

0

No. You cannot put a datastore in a table.

0

U simply cant.

0

Then how would you save a table?

0

Give it a go!

1 answer

I'm assuming you mean how do you save a table to a datastore.

You can do this by using HttpServices JSONEncode and JSONDecode

E.g.

--Assuming you have a datastore named datastore and key has a value

local hs = game:GetService("HttpService")

local exampleSave = {"hi", "my name is potato", "nice to meet you"}

function setAsync(t, key)
	local tosave = hs:JSONEncode(t)
	datastore:SetAsync(key, tosave)

function getAsync(key)
	local toDecode = datastore:GetAsync(key)
	local decoded = hs:JSONDecode(toDecode)
	return decoded

setAsync(exampleSave, "example_key")

print(getAsync("example_key")) --Outputs table and hex

How JSONEncode works is that it converts a table to a json string so it can be saved, however using this you can not save any Instances.

JSONDecode works by turning the json string back into a table so it can be used in lua.

Hope this helps!

Read more here:

Datastores HttpService

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