I have data store script which should save player bool values names in his inventory folder to data store table, but it prints "ItemsDataSaved!’ but table is empty. Here is script:
local DataStoreService=game:GetService("DataStoreService")
local InventoryDS=DataStoreService:GetDataStore("InventoryDS")
local RS=game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(player)
local inventory=Instance.new("Folder", player)
inventory.Name="Inventory"
local itemsData
local success, errormessage=pcall(function()
itemsData=InventoryDS:GetAsync(player.UserId)
end)
if success then
print("SUCCESS")
else
print(errormessage)
end
player.CharacterAdded:Wait()
wait(4)
if success and itemsData then
for i,itemName in ipairs(itemsData) do
for _,v in pairs(RS.Cases:GetDescendants()) do
if v:IsA("Model") and v.Name== itemName then
local itemValue=Instance.new("BoolValue", player.Inventory)
itemValue.Name=itemName
end
end
end
end
end)
local function saveData(player)
local itemsTable={}
for i,item in ipairs(player.Inventory:GetChildren()) do
table.insert(itemsTable,item.Name)
end
local success,errormessage=pcall(function()
InventoryDS:SetAsync(player.UserId,itemsTable)
end)
print(table.concat(itemsTable,", "))
if success then
print("ItemsDataSaved!")
else
print(errormessage)
end
end
game.Players.PlayerRemoving:Connect(function(player)
saveData(player)
end)
game:BindToClose(function()
for _,player in pairs(game.Players:GetPlayers()) do
saveData(player)
print("btc")
end
end)

I constantly forget to do it through the server, thanks for the reminder!