So I have recently created several more developer product purchases that do the same thing as my first one but more lives. I was trying to convert it over to the multi developer product purchase script to get them all working since it obviously breaks all but the last one in this script if I repeat it. I tried multiple times to convert it and was just wondering if anyone could help me with the conversion.
Here is a portion of my current script for just one developer product purchase since the rest would be a copy of the conversion with different values.
local mpService = game:GetService("MarketplaceService") mpService.ProcessReceipt = function(purchaseInfo) local plr = game:GetService("Players"):GetPlayerByUserId(purchaseInfo.PlayerId) if not plr then return Enum.ProductPurchaseDecision.NotProcessedYet end if purchaseInfo.ProductId == 55131820 then local Lives = plr.leaderstats.Souls; Lives.Value = Lives.Value +1 end return Enum.ProductPurchaseDecision.PurchaseGranted end
and Here is a portion of the multi developer product purchase script from the wiki.
local Products = { -- productId 1111 for a heal up [1111] = function(receipt,player) -- Check if we can actual heal him if not player.Character then return end local human = player.Character:findFirstChild("Humanoid") if not human then return end -- Heal him, and return true, indicating the purchase is done human.Health = human.MaxHealth return true end; -- productId 2222 for 100 gold [2222] = function(receipt,player) -- again, do checks, this time for the Gold value local stats = player:findFirstChild("leaderstats") local gold = stats and stats:findFirstChild("Gold") if not gold then return end -- no leaderstats, or "Gold" in them gold.Value = gold.Value + 100 -- give gold return true -- tell them of our success end;
I tried changing the
local stats = player:findFirstChild("leaderstats") local gold = stats and stats:findFirstChild("Gold") if not gold then return end -- no leaderstats, or "Gold" in them gold.Value = gold.Value + 100 -- give gold
portion of the script to my values but with no such luck. Anyone who can help would be greatly appreciated.
Without setting up a dictionary, you can simply just add elseif
statements to check for multiple IDs like so:
local mpService = game:GetService("MarketplaceService") mpService.ProcessReceipt = function(purchaseInfo) local plr = game:GetService("Players"):GetPlayerByUserId(purchaseInfo.PlayerId) if not plr then return Enum.ProductPurchaseDecision.NotProcessedYet end if purchaseInfo.ProductId == 55131820 then local Lives = plr.leaderstats.Souls; Lives.Value = Lives.Value +1 elseif purchaseInfo.ProductId == 40592456 then local Lives = plr.leaderstats.Souls; Lives.Value = Lives.Value +2 elseif purchaseInfo.ProductId == 50123452 then local Lives = plr.leaderstats.Souls; Lives.Value = Lives.Value +3 end return Enum.ProductPurchaseDecision.PurchaseGranted end
Hope this helps and you can continue on adding more with these examples. If it doesn't work or you need help, comment below. If it's perfectly fine then just accept it as the answer and upvote of you feel like it!