The title says it all.
COMMUNITY QUESTION
Can you save a table in DataStoreService?
1 answer
When saving a table into a DataStore, it does not change the way of saving it, meaning that you should write the same things when you save any other value(although, if the table contains an instance, the script will not save the table)
I'll give you a little example of how to use it.
-- this script inserts the name of a table(string) which it's saved in a datastore with the game id when the player leaves.
local MyStore = game:GetService('DataStoreService'):GetDataStore('MyDataStore')
local tab = {}
local Plrs = game:GetService('Players')
Plrs.PlayerAdded:Connect(function(plr)
local data
local s, e = pcall(function()
data = MyStore:GetAsync(game.GameId)
end)
if s then
if data ~= nil then
tab = data
table.insert(tab, plr.Name)
else
table.insert(tab, plr.Name)
end
else
warn(e)
end
print(tab)
end)
Plrs.PlayerRemoving:Connect(function()
local s, e = pcall(function()
MyStore:SetAsync(game.GameId, tab)
end)
if not s then
warn(e)
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
im kinda new to datastoreservice and scripting overall so thats a bit lengthly to understand right now (and i deducted some errors for what i have to do so i figured out a new plan) but thanks! i can use this as a future reference if i ever wanna put a table in it
sorry if it had any errors, I couldn't see them because I made the code inside the website