I am trying to make a save system that uses only one key, and in order to do this I need to have a table inside a table.
function saveData(player)
local plrdata = {}
plrdata.Coins = player.leaderstats.Coins.Value
plrdata.Stars = player.PlayerStats.Stars.Value
plrdata.Slots = player.PlayerStats.Slots.Value
local playerblobs = {}
for i,v in pairs(player.Blobs:GetChildren()) do
playerblobs[v.Name] = {}
local lb = playerblobs[v.Name]
lb.Level = v.Stats.Level.Value
end
table.insert(playerblobs, plrdata)
playerdata:SetAsync(player.userId, plrdata)
end
However, when I do this, then I print everything in the save nothing is there. Is there another way to do this?
Are you trying to insert playerblobs into plrdata? If so, you have table.insert’s arguments mixed up. The first argument is the table you want to put the second argument in.
You cannot use table.insert for this iirc, as it is intended for use with arrays. Datastores expect the tables you’re saving to either be completely indexed by string, or by integer, not mixed together.
You should instead do something like plrdata.Blobs = playerblobs.
Not only are the two parameters switched, but you’re going to end up with a table with numerical and string keys. Since tables with mixed string and numerical keys can’t be encoded into JSON (and thus can’t be saved into your datastore), you’re going to encounter a datastore error.