This script saves the player’s inventory. No errors are coming up, but it does not save.
local DataStore = game:GetService("DataStoreService"):GetDataStore("Inventory_Saving")
local replicatedStorage = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(player)
local inventory = Instance.new("Folder")
inventory.Name = "CardInventory"
inventory.Parent = player
local data
local succ, er = pcall(function()
data = DataStore:GetAsync("CardInventory-"..player.UserId)
print("recovered inventory")
end)
if succ and data then
for _, cardName in pairs(data) do
if replicatedStorage.Cards:FindFirstChild("cardName") then
local cardValue = Instance.new("StringValue")
cardValue.Name = cardName
cardValue.Parent = inventory
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local cardTable = {}
for _, card in pairs(player.CardInventory:GetChildren()) do
table.insert(cardTable,card.Name)
print(card.Name)
end
local succ, er = pcall(function()
DataStore:SetAsync("CardInventory-"..player.UserId,cardTable)
end)
if succ then
print("saved")
else
print(er)
end
end)
All the prints are working except “saved”.
Thanks!