I’m trying to make a system where player’s items will be saved in datastores. The items are just collectables, and are just string values in a folder in the player:

At the moment the script for saving looks like this:
local function saveData(player)
local iteminventory = {}
for _, item in pairs(player.Collectables:GetChildren()) do
table.insert(iteminventory,item.Name)
print(iteminventory)
end
local success, errorMsg = pcall (function()
Datastore:SetAsync(player.UserId,{iteminventory})
end)
if success then
print("saved")
else
print(errorMsg)
end
end
game.Players.PlayerRemoving:Connect(function(player)
saveData(player)
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end)
I’ve tried rewriting the code several times based off tutorials and other people’s save systems and I think this is as close as I’ve been able to get and fixed several other problems other than this one. I’m able to get the tables to be made but nothing will be saved in them shown with a plugin that lets me see the datastore:

“TestBird” has not been put into the table :<
Please let me know what I can do to fix this, thank you for your time!