Is there a way to DataStore inside of a table?
COMMUNITY QUESTION
How do you do DataStore in a table?
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:
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
No. You cannot put a datastore in a table.
U simply cant.
Then how would you save a table?
Give it a go!