Hello.
I'm kind of new to datastores, I can save a single value, however more than that is where the issues begin.
So, basically, I'm trying to add multiple integer values into a folder called "inventory", then when the player leaves, the data saves, and when they rejoin, the values load back into the user's folder, named "inventory".
Here's my script.
local DS = game:GetService("DataStoreService"):GetDataStore("Inventories")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder",player)
folder.Name = "inventory"
local inventory = {}
inventory.Name = "inventory"
local dataKey = "userkey_"..player.UserId
local data
local success,errormsg = pcall(function()
data = DS:GetAsync(dataKey)
end)
if not success then
warn("Error when retrieving data for "..player.Name..". Error: "..errormsg)
folder.Value = nil
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success,errormsg = pcall(function()
for i, v in pairs(game.Players[player].inventory:GetFirstChildOfClass("IntValue").Value) do
DS:SetAsync("userkey_"..player.UserId,player.inventory.v.Value)
end
end)
if not success then
warn("Unable to save for "..player.Name..". Error: "..errormsg)
end
end)
The error:
Unable to save for 7z99. Error: ServerScriptService.Saving game data:32: bad argument #2 (string expected, got Object)
Thanks in advance for the help!

7 comments
Thanks! Could you add some comments to explain what's going on? This stuff is pretty new to me.
There ended up being an issue: "Inventory is not a valid member of Folder", and then at the end, it says the inventory was not saved because it wasn't updated.
Oh gosh sorry about that I made some mistakes
Lemme update it
There that should work and also delete the ? idk why it shows that
It appears to be the same.
There was " but sideways