game.Players.PlayerRemoving:Connect(function(plr) print("running removing") local priorData = dataStore:GetAsync(plr.UserId) print('loaded old data') local dataToSave = { ['gagueStats'] = { ['gglvl'] = plr.gg.Value, ['ggxp'] = plr.ggEXP.Value, ['tp'] = plr.tp.Value, ['str'] = plr.str.Value, ['strxp'] = plr.strEXP.Value, ['int'] = plr.int.Value, ['intxp'] = plr.intEXP.Value, ['end'] = plr['end'].Value, ['ednxp'] = plr.endEXP.Value, ['dex'] = plr.dex.Value, ['dexxp'] = plr.dexEXP.Value }, ['appearanceStats'] = priorData['appearanceStats'], ['spiderwebCompletion'] = priorData['spiderwebCompletion'], ['inventory'] = { }, ['gold'] = plr.gold.Value } print('table created') for i,v in pairs(plr.inv:GetChildren()) do print(v) table.insert(dataToSave['inventory'], i, v.Name) end print('inv stuff added') dataStore:SetAsync(plr.UserId, dataToSave) print('saved') end)
The goal is to take everything inside a folder named "inv" inside the player and save it under the inventory table in the data table, however, when I load back into the game there are no items in my inventory except for one copy of trash when there should be two (I have a script to add it to my inventory every time I load in)
When I tried print debugging, it only printed down to "running removing" which is the first print. Why would nothing after this run? There are no errors for it either.
You could use a separate script for the inventory i suggest you creating a folder with the items in replicated storage and storing only the items name, so you can clone them and put it on player's inventory
local datastorage = game:GetService("DataStorage") -- get the service local inventoryStorage = datastorage:GetDataStore("inventory") -- get the data store game.Players.PlayerAdded:connect(function(plr) local inv_save = inventoryStorage:GetAsync(plr.UserId) or {""} -- anything you want to do with the inventory here, i don't really know how your system works end) game.Players.PlayerRemoving:connect(function(plr) local items = plr.inv:GetChildren() local stored = {} for _,v in pairs(items) do table.insert(stored,#stored + 1,v.Name) end inventoryStorage:SetAsync(plr.UserId,stored) local functiontest1,functiontest2 = pcall(function() -- just to be sure it saved. inventoryStorage:UpdateAsync(plr.UserId,stored) end) end)