Hello developers, I am currently scripting a developer product system which should grant the player necessary rewards when it gets bought.
However, as the following function runs, it only grants the first products reward and not the others. The problem is, the function doesn’t pass the second and the other if statements and it should. Here is the script. Note: There is no issue with the prompts. Also, the first product gets granted too.
local MarketPlaceService = game:GetService("MarketplaceService")
productIds = {
id1, id2, id3, id4, id5
}
local function giveProductReward(reward, player)
player:WaitForChild("leaderstats"):WaitForChild("Money").Value += reward
end
MarketPlaceService.ProcessReceipt = function(receiptInfo)
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
for _, productIdFromTable in pairs(productIds) do
if receiptInfo.ProductId == productIdFromTable and player then
if productIdFromTable == id1 then
giveProductReward(10000, player)
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif productIdFromTable == id2 then
print("second prodct")
giveProductReward(30000, player)
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif productIdFromTable == id3 then
giveProductReward(100000, player)
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif productIdFromTable == id4 then
giveProductReward(500000, player)
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif productIdFromTable == id5 then
giveProductReward(1000000, player)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
else
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end
end