So I was having trouble with developer products because I was using more than 1 receiptInfo, so I combined both my donation board script and my obby skip stage developer product into one script.
I tested the skip stage dev product and it works as intended.
My questions are the following: Is this method going to ensure that the skip stage dev product will always work? Will it break if too many people buy it in a small amount of time? Is there any way to improve it?
Here is the receiptInfo part of the code (I took off the other part because it was the donation board):
function ReceiptHandler()
warn("Donation Board: ProcessReceipt Activated")
game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
local plrPurchased = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
local devProductID = 1190837096
if not plrPurchased then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if receiptInfo.ProductId == devProductID then
if tonumber(plrPurchased.leaderstats.Stage.Value) < #workspace.Stages:GetChildren() - 1 then
plrPurchased.leaderstats.Stage.Value = plrPurchased.leaderstats.Stage.Value + 1
else
--plrPurchased.leaderstats.Stage.Value = "End"
game.StarterGui.SkipStage.TextButton.Visible = false
plrPurchased.leaderstats.Stage.Value = plrPurchased.leaderstats.Stage.Value + 1
end
plrPurchased:LoadCharacter()
return Enum.ProductPurchaseDecision.PurchaseGranted
end
local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
local numberBought = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory"):IncrementAsync(playerProductKey, 1)
local ProductBought = game:GetService("DataStoreService"):GetDataStore("PurchaseHistoryCount"):IncrementAsync(receiptInfo.ProductId, 1)
local PlayerFound = false
for i, v in pairs (game.Players:GetChildren()) do
if v:IsA('Player') then
if v.userId == receiptInfo.PlayerId then
for _, p in pairs (Products.Products) do
if p.ProductId == receiptInfo.ProductId then
if v ~= nil then
PlayerFound = true
game:GetService("DataStoreService"):GetOrderedDataStore(GetData()):IncrementAsync(receiptInfo.PlayerId, p.ProductPrice)
end
end
end
end
end
end
if PlayerFound ~= true then
return Enum.ProductPurchaseDecision.NotProcessedYet
else
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
end