everytime you purchase something it adds to the table and that it saves
i dont know how or if its possible that you can save a table when adding a value without knowing what the value is gonna be
i read so much but nothing helped
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
local purchases = {}
local function saveData(player) -- The functions that saves data
local success, err = pcall(function()
purchaseHistoryStore:SetAsync(player.UserId, purchases) -- Save the data with the player UserId, and the table we wanna save
end)
if success then -- If the data has been saved
print("Data has been saved!")
print(purchases)
else -- Else if the save failed
print("Data hasn't been saved!")
warn(err)
end
end
players.PlayerAdded:Connect(function(plr)
local success, purchases = pcall(function()
return purchaseHistoryStore:GetAsync(plr.UserId)
end)
if success then
print(purchases)
end
end)
players.PlayerRemoving:Connect(function(plr)
saveData(plr)
end)
promptPurchaseEvent.OnServerEvent:Connect(function(plr, id, item)
if not id then
return
end
if item then
mps:PromptPurchase(plr, id)
end
end)
local MarketplaceService = game:GetService("MarketplaceService")
local function onPromptPurchaseFinished(player, assetId, isPurchased)
if isPurchased then
print(player.Name, "bought an item with AssetID:", assetId)
purchases[#purchases+1] = assetId
saveData(player)
else
print(player.Name, "didn't buy an item with AssetID:", assetId)
end
end
Its like if the player purchases something it adds to the table and then it saves
and its a catalog game so u cant know the ids already
and the variable called purchases is the table
and i dont know how to remove the local
What do you mean with you can’t know the value?
I see in that script that you are indexing it in that table and saving it.
Corresponding to the purchases variable, I don’t meant to remove the local exactly, after the success set it.