So I’m working on an inventory system, when a player joins the game, there is folders created as such:
So what I wanted to do was actually way easier thought than done, I figured that when saving player data, I would loop through these folders (i would use values for ‘items’ and ‘materials’ etc.) and create a dictionary for the players stuff, the code I did for this was REALLY messy and confusing, so, look at it at your own risk.
game.Players.PlayerRemoving:Connect(function(player)
local toSave = {}
local Equipped = toSave.Equipped
local Materials = toSave.Materials
local Items = toSave.Items
local Inventory = player.Inventory
for _,v in pairs(Inventory.Equipped:GetChildren()) do
local item = toSave.Items[v.Value]
end
for _,v in pairs (Inventory.Materials:GetChildren()) do
local item = toSave.Materials[v.Value]
local quan = v.Quantity
local quantity = toSave.Materials[v].quan
end
for _,v in pairs (Inventory.Items:GetChildren()) do
local item = toSave.Items[v.Value]
end
local s, e = pcall(function()
InventoryDS:SetAsync(player.UserId, toSave)
end)
if s then
print("Success!")
end
if e then
print("Error!")
end
end)
I know there’s a lot of things that you can critique here, eg: the method of saving, using the userid as a key, so on and so forth, I’m aware of this and I just typed this all up to try and get something going at least.
This is what an item would of looked like in the explorer:
I was trying to add this item to the dictionary, I’m guessing that I’m doing it wrong, I’m not too sure how I can add that item to the dictionary, I’m aiming for the dictionary to look something along the lines of
v.Value was my attempt at saving the value of the integer / string values stored in the player’s inventory folder. At this point I don’t know how to save value into the dictionary.
Might I ask, how would you read from the dictionary then? Supposing I :GetAsync() and retrieve the players data, how could I access for example the wood inside materials with quantity 50?