For some reason, if you buy the product more than once, it will activate the reward multiple times. Why?
local MarketplaceService = game:GetService("MarketplaceService")
local character1, slotid = 42907443, 45098689
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
MarketplaceService.ProcessReceipt = function(receiptInfo)
local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
if PurchaseHistory:GetAsync(playerProductKey) then
return Enum.ProductPurchaseDecision.PurchaseGranted --We already granted it.
end
-- find the player based on the PlayerId in receiptInfo
for i, player in ipairs(game.Players:GetPlayers()) do
if player.userId == receiptInfo.PlayerId then
-- check which product was purchased (required, otherwise you'll award the wrong items if you're using more than one developer product)
if receiptInfo.ProductId == character1 then
-- handle purchase. In this case we are healing the player.
player.skins[tostring(player.PlayerGui.GUI.main_menu.character_select.buy_skins.skin.Value)].Value = player.skins[tostring(player.PlayerGui.GUI.main_menu.character_select.buy_skins.skin.Value)].Value+ 1
elseif receiptInfo.ProductId == slotid then
-- handle purchase. In this instance we're giving the player 100 extra gold.
player.data.slots.Value = player.data.slots.Value + 1
end
end
end
-- record the transaction in a Data Store
PurchaseHistory:SetAsync(playerProductKey, true)
-- tell ROBLOX that we have successfully handled the transaction (required)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
