I’m making a building game where all of any one player’s builds are stored in one model. I wrote this script so that players could easily load and save their hard work, but it isn’t working.
The script works by making one main table (what actually gets saved) and then putting a bunch of smaller tables inside (the individual builds). A player can access any individual build with a slot, which is basically just an index in the main table. However, whenever I serialize a build and add it to the main array, and then attempt to get that array via a datastore, it just returns an empty table with one empty table inside, like this:
{ [1] = {} }
I don’t know why this is happening, but if any of you guys see anything wrong let me know. Script is down below 
--++++++++Begin save handling++++++++
--++++++++Begin save handling++++++++
local function encodeGroup(group)
local encodedMain = {}
for i,v in pairs(group:GetChildren()) do
local encodedPart = {}
encodedPart[1] = v.Position
encodedPart[2] = v.BrickColor
encodedPart[3] = v.Material
encodedPart[4] = v.Transparency
table.insert(encodedMain, encodedPart)
end
if encodedMain then
return encodedMain
else
return nil
end
end
local function decodeTable(tablelol, plr)
local group = getGroup(plr)
for i,v in pairs(tablelol) do
local part = Instance.new("Part")
part.Position = v[1]
part.BrickColor = v[2]
part.Material = v[3]
part.Transparency = v[4]
part.Parent = group
end
end
local function saveToSlot(plr, slot)
local encodedGroup = encodeGroup(getGroup(plr))
local updated = {}
local success, err = pcall(function()
local save = dataStore:GetAsync(plr.UserId)
if save ~= nil then
updated = save
end
updated[slot] = encodedGroup
dataStore:SetAsync(plr.UserId, updated)
print(dataStore:GetAsync(plr.UserId))
end)
end
local function loadSave(plr, slot)
local success, err = pcall(function()
local save = dataStore:GetAsync(plr.UserId)
print(save)
decodeTable(save[slot])
end)
end