Basically I’m stuck at saving multiple things in one datastore . Here’s what I mean
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
There should be multiple values BUT It gave me only ONE instead . So any idea how to prevent this . Any help is very appreciated
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
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
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!
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