local DS = game:GetService("DataStoreService") local InventoryStore = DS:GetDataStore("InventoryStore") local function save(player) local playerInventory = player.Inventory:GetChildren() local playerSave = {} for i = 1, #playerInventory do print(playerInventory[i].Value) table.insert(playerSave, playerInventory[i].Value) end local success, failure = pcall(function() InventoryStore:SetAsync(player.UserId, playerSave) end) if success then print("Saving Success!") end if failure then warn("Critical Save failure. Data of "..player.Name.." not saved.") end end game.Players.PlayerAdded:Connect(function(player) local inventory = Instance.new("Folder", player) inventory.Name = "Inventory" Instance.new("StringValue", inventory).Value = "Test" local success, PlayerComputerTable = pcall(function() InventoryStore:GetAsync(player.UserId) end) if success then print(PlayerComputerTable) end end) game.Players.PlayerRemoving:Connect(function(playerRemoving) save(playerRemoving) end) game:BindToClose(function() for _, client in ipairs(game.Players:GetPlayers()) do coroutine.wrap(save)(client) end end)
This code isn't erroring nor saving the Player's data.