Table has too many results to unpack?

I had noticed that people lost their save files because they couldn’t undo their massive creations they overwrote by accident, so i went to check it out and noticed that table.unpack has a limit.
image

Why is there a limit for table.unpack and is there a way to bypass it? People are risking on losing their massive creations they have been working on for weeks.

You shouldn’t be using table.unpack() in the first place for this sort of application, what are you passing the returned tuple to? Some code would be appreciated.

1 Like
pcall(function()
	Save = {unpack(PlayerData["Backup" .. SlotNum])}
end)
local succes,message = pcall(function()
	PlayerData["Backup" .. SlotNum] = {unpack(PlayerData["Slot"..tostring(SlotNum)].Craft)}
end)

I need to unpack the aircraft from the table to make it noncyclic so that it can be saved to the datastore.

I’m still having some trouble understanding how you’re storing your data, how is it formatted before you’re unpacking it?

local savetable = {craft = {content}, name = ""}
local backupsave = {content}

local tempstorage = unpack(backupsave)

backupsave = unpack(savetable.craft)

savetable.craft = tempstorage

This doesn’t help me, what is content? I think you may want to look into Serialization, converting part objects into data storable in DataStores. I’m not an expert on the topic but this is how one of my friends solved a similar problem.

So you are unpacking a table to then store back into a table?

the content is the stored aircraft table with strings for every single block.

Into a different table, yes. It has to be noncyclic, otherwise attempting to save the full table will fail to save.

So your table is holding references to other members of the same table?

Ex.

local Array0 = {Text = "String"}
local Array1 = {Text = "String"}

Array0.Array1 = Array1
Array1.Array0 = Array0

print(Array0.Array1.Array0.Array1.Text)

u should Loop trough the table instead of using Unpack. since there is a limit on how many values there can be in a tuple (i think)

I have a saving table and a backup table.

The saving table will be saved once the player leaves the game.

The backuptable gets loaded onto the craft from the saving table once the player presses the undo button and the current craft from the saving table will get moved to the backup table.

Both saving tables holds strings with blockdata.

It sounds to me as if table.unpack() is not a viable method for this. As @LukaDev_0 suggested you should be looping through rather than using unpack and passing everything to a new table.

But wouldn’t that lag the game like crazy?

Shouldn’t, new improvements with Luau have made iterator functions significantly more efficient.

What would be the fastest way to acomplish it? Is looping through the table faster than table.unpack?

local cloneTable = {}
for k, v in pairs(PlayerData["Slot"..tostring(SlotNum)].Craft) do
     cloneTable[k] = v
end
PlayerData["Backup" .. SlotNum] = cloneTable

I’m not sure if it’s faster or not, but this is the only way around the table.unpack limit. It’s not going to make that much of a difference.