Need help saving multiple folder that containing multiple value

Hi there,

Basically I’m stuck at saving multiple things in one datastore . Here’s what I mean
Screenshot (443)
so basically I wanna save the all the folders AND all the values in side it but I only got one value from the data . Here’s what I mean

table: 0x4ab292b4626528fe = {
                    ["Guns"] =  ▼ table: 0x5201cb4fad0dc7be = {
                       [1] = "Map3"
                    },
                    ["Kill Animation"] =  ▼ table: 0x5d02e2d4c97a467e = {
                       [1] = "Map3"
                    },
                    ["Kill Effect"] =  ▼ table: 0xe4e5232d68f1cfde = {
                       [1] = "Map3"
                    },
                    ["Pets"] =  ▼ table: 0x95a213362abd2cfe = {
                       [1] = "Map3"
                    }
                 }

There should be multiple values BUT It gave me only ONE instead . So any idea how to prevent this . Any help is very appreciated :slight_smile: :slight_smile:

the current code:

local TableToSave = {}
	
	for i , v in pairs(Player.Inventory:GetChildren()) do
		---table.insert(TableToSave , v.Name)
		for index , value in pairs(v:GetChildren()) do
			TableToSave[v.Name] = {value.Name}
		end
	end

	local data
	
	local succ , err = pcall(function()
		data = PlayerInventory:SetAsync(Player.UserId , TableToSave)
	end)
	if succ then
		warn(TableToSave)
	else
		error(err)
	end

You might need to use http service to encode the table as a json string!

I got it working but there’s a problems

  table: 0x5baabca30ccd2d12 = {
                    ["Guns"] = "["Cash","Exp","Level","Cash","Exp","Level"]",
                    ["Kill Animation"] = "["Cash","Exp","Level","Cash","Exp","Level","Cash","Exp","Level"]",
                    ["Kill Effect"] = "["Cash","Exp","Level","Cash","Exp","Level","Cash","Exp","Level","Cash","Exp","Level"]",
                    ["Pets"] = "["Cash","Exp","Level"]"
                 }

how to separate this

the current script:

local TableToSave = {}
	local ValueToTransfer = {}
	
	for index , value in pairs(self.Player.Inventory:GetChildren()) do
		for _  , child in pairs(value:GetChildren()) do
			
			table.insert(ValueToTransfer , child.Name)
			TableToSave[value.Name] = httpService:JSONEncode(ValueToTransfer)
		end
	end
1 Like

My bad sorry didn’t read it properly!

Sooooo … what should I do in this situations??

Hmm the code looks a bit confusing. Try writing out a base Lua table for starting players, then creating a packing and unpacking function that you call on player added and player removing respectfully. I would write a coffee sample but I’m on mobile right now, sorry. Looks like you’re unpacker is working though. Otherwise on your problem i think the problem is obviously in the TableToSave[v.Name] = {value.Name}. try rewriting this line, with a chart of the table you want and the objects within the folder. Sorry i can’t offer better advice right now! If you still have the problem in the morning I’ll answer it on my computer!

Ok…so I manage to get it working . Here’s the example:

 ▼ table: 0x00c133a9456bfa81 = {
                    ["Guns"] =  ▼ table: 0x1b097076a719ff01 = {
                       [1] =  ▼ table: 0x789286c4bd4b18c1 = {
                          ["Gun1"] = true
                       },
                       [2] =  ▼ table: 0xb06dd479509bd581 = {
                          ["Gun2"] = true
                       }
                    },
                    ["Kill Animation"] =  ▼ table: 0x439e94cc65b363c1 = {
                       [1] =  ▼ table: 0x2f2453c235ce2701 = {
                          ["Gun1"] = true
                       },
                       [2] =  ▼ table: 0x0efcbaef881de041 = {
                          ["Gun2"] = true
                       }
                    },
                    ["Kill Effect"] =  ▼ table: 0x9a73d5df346f0141 = {
                       [1] =  ▼ table: 0x9a34e874646e14c1 = {
                          ["Gun1"] = true
                       },
                       [2] =  ▼ table: 0xbc7a8d6dee56fe81 = {
                          ["Gun2"] = true
                       }
                    },
                    ["Pets"] =  ▼ table: 0xcc29f988ba5bd641 = {
                       [1] =  ▼ table: 0x5ab624dd1de47c81 = {
                          ["Gun1"] = true
                       },
                       [2] =  ▼ table: 0x62de8fb4bae1bec1 = {
                          ["Gun2"] = true
                       }
                    }
                 } 

is there any way to remove the index number??
I want something like this:

["Guns"] =  ▼ table: 0x1b097076a719ff01 = {
                 
                          ["Gun1"] = true;
                          ["Gun2"] = true
                       }

instead of:

["Guns"] =  ▼ table: 0x1b097076a719ff01 = {
                       [1] =  ▼ table: 0x789286c4bd4b18c1 = {
                          ["Gun1"] = true
                       },
                       [2] =  ▼ table: 0xb06dd479509bd581 = {
                          ["Gun2"] = true
                       }

that’s all :slight_smile:

the script:

for index , value in pairs(self.Player.Inventory:GetChildren()) do
		TableToSave[value.Name] = {}
		
		for _  , child in pairs(value:GetChildren()) do
			--table.insert(TableToSave[value.Name] , child.Name)
			table.insert(TableToSave[value.Name] , {[child.Name] = child.Value})
			--TableToSave[value.Name] = {[child.Name] = child.Value}
		end
		
	end
1 Like

Ok i found the solutions . All I need to do is just to make t like this:

TableToSave[value.Name][child.Name] = child.Value

instead of this:

table.insert(TableToSave[value.Name] , {[child.Name] = child.Value})

@Shiroudan thanks for taking your time to help me :slight_smile:

Also I found the solution when I was bathing . So I guess god is helping me also :sweat_smile:

3 Likes