Need help removing uneeded ["1"]s from a dictionary

I am making a function that packs folder data into a dictionary table so that I can use it in datastores.

I want to achieve the same format, but without the [“1”]s in it, since they hold no importance to the unpackaging program I am going to write and would only take up time.

["DataStorage"] =  ▼  {
   [1] =  ▼  {
      ["Achievements"] =  ▼  {
         [1] =  ▼  {
            ["ClearAGate"] =  ▶ {...},
            ["FinishTheTutorial"] =  ▶ {...},
            ["JoinTheGame"] =  ▶ {...},

image

Here is the code I am using to package it.

local function PackageData(file)
	local data = {};
	
	for _, child in pairs (file:GetChildren()) do
		if (child.ClassName == "Folder") then
			data[child.Name] = {PackageData(child)};
		else -- value class
			data[child.Name] = child.Value;
		end
	end--]]
	
	return data;
end

function PlayerData:GetDataPackage()
	local DataPackage = PackageData(self.DataStructure);
	
	return DataPackage;
end

I tried making a dictionary before calling the function for the first time in “GetDataPackage”, but when I do that it doesn’t read the data in the same way. If anyone has some insight into a solution then I’d appreciate it!

for _, child in pairs (file:GetChildren()) do
		if (child.ClassName == "Folder") then
			data[child.Name] = PackageData(child); -- removed table here
		else -- value class
			data[child.Name] = child.Value;
		end
	end

This should fix your issue, let me know if it still occurs!

1 Like

Ye that was it. Added that cuz I thought you needed the {} in order to add more than 1 object, but obviously that isn’t the case. Thanks for the help!

1 Like

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