- What do you want to achieve?
A saving dev product that saves when a player buys a product, I already have a datastore that already saves the values!
- What is the issue?
The issue is that it doesn’t save, when a player leaves it goes back to the original amount and I already have a datastore that works fine it just doesn’t work when a player buys dev products!
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Finding a solution.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
--[product id] = amount of strength
local products = {
[1232282811] = 10000,
[1232282877] = 100000,
[1232282925] = 1000000,
[1232282987] = 10000000,
[1232283029] = 100000000,
[1232283060] = 1000000000
}
--Gems--
local products2 = {
[1232275748] = 10000,
[1232275772] = 100000,
[1232275792] = 1000000,
[1232275869] = 10000000,
[1232275957] = 100000000,
[1232275978] = 1000000000
}
--Coins--
local products3 = {
[1232272876] = 10000,
[1232272728] = 100000,
[1232272939] = 1000000,
[1232273020] = 10000000,
[1232273262] = 100000000,
[1232273458] = 1000000000
}
local products4 = {
[1215148092] = 5,
[1215148421] = 10,
[1215148581] = 50,
[1215148705] = 100,
[1215148803] = 500
}
MarketplaceService.ProcessReceipt = function(receiptInfo)
--pcall in case it fails
local Success, Error = pcall(function()
--there is a function for this
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
local leaderstats = player:FindFirstChild("leaderstats")
local RDonations = player:FindFirstChild("R$ Donated")
local Strength = leaderstats:FindFirstChild("Strength")
local Gems = leaderstats:FindFirstChild("Gems")
local Coins = leaderstats:FindFirstChild("Coins")
local amount = products[receiptInfo.ProductId]
Strength.Value += amount or 0 --if the product isn't part of the dictionary, we ignore it.
local amount2 = products2[receiptInfo.ProductId]
Gems.Value += amount2 or 0 --if the product isn't part of the dictionary, we ignore it.
local amount3 = products3[receiptInfo.ProductId]
Coins.Value += amount3 or 0 --if the product isn't part of the dictionary, we ignore it.
local amount4 = products4[receiptInfo.ProductId]
RDonations.Value += amount4 or 0 --if the product isn't part of the dictionary, we ignore it.
end)
if Success then
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn(Error)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end
Thank you in advance!