How to change the name of a key where the Array is stored in a main Array for datastore?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    As mentioned in the title, I want to change the name inside the array so I could access them using a string.

  2. What is the issue?
    I have no clue how to approach this, so I am asking to see if there is a way to do this.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have looked up how I can change a name of a key in a dictionary, but in terms of how to set a name for the key, I could not find a solution (or maybe I did not look deep enough).

-- What is printed: 
{
  [1] = {},
  [2] = {}
}
-- What I want to print: 
{
  ["buyStats"] = {},
  ["equipStats"] = {}
}

Pseudocode:
local mainSave = {}

local buyStats = {}

for in pair buyStats do
  add number into buyStats 
add buyStats to mainSave

local equipStats = {}

for in pair equipStats do
  add number into equipStats 
add equipStats to mainSave

save mainSave 

Apologies, but I am struggling to understand what you want. In your code there are many syntax errors and I assume that is because you are trying to describe it, but I am unsure.

So basically I have a code that saves an array with multiple other arrays, the problem is I don’t know how I can get it to print out the way I have mentioned in the post, or in other words have those keys (1, 2, etc) to have a name in strings instead of numbers. I want it in strings so that I could access it using the key’s name when assigning it to their respectful folders

If you already have them ordered as 1 and 2, you could do something like this:

local gottenData = -- Data from the datastore
local newDictionary = {
    ["buyStats"] = {};
}
for i,v in pairs(gottenData[1]) do
    table.insert(newDictionary["buyStats"], v)
end

If your table is nested (a table inside of a table), then consider looking into deep cloning it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.