Table A = data (not Data) Table B = CompTable
I'm trying to combine A with B, where A overwrites B, but if something exists in B but not in A, B adds the value to A. I've tried several times and I'm currently lost..
"attempt to index field '?' (a nil value)"
local CompTable = {
["Stats"] = {
["Money"] = 100;
["Exp"] = 0;
["Placements"] = {
["PropA"] = {
["Rotation"] = 2;
["Position"] = Vector2.new(1, 5)
};
};
["Inventory"] = {
["1"] = 10945;
};
};
["Time"] = {
["LastJoin"] = false;
["LastCrate"] = false;
};
["Settings"] = {
["DarkUITheme"] = false;
["BlurFX"] = false;
["ColorCorrectionFX"] = false;
};
}
function module:combineTables(data)
if not data or data == false then return CompTable end
local DataTable = {}
local pass, reason = pcall(function()
for Index, DString in pairs(CompTable) do
DataTable[tostring(Index)] = {}
for Index2, DString2 in pairs(DString) do
if data[tostring(Index)][tostring(Index2)] == true then --error
DataTable[tostring(Index)][tostring(Index2)] = data[tostring(Index)][tostring(Index2)]
else
DataTable[tostring(Index)][tostring(Index2)] = DString
end
end
end
end)
print(pass, reason)
return DataTable
end

1 comment
By the way, if you're merging in player data, this is super smart, and I highly recommend it. Avoids issues where players join old servers and then new servers!