I am trying to make a simulator but I have problem with developer products. When you purchase product it does not give you money every time. Sometimes it works but sometimes it does not. Here is the script: local MarketplaceService = game:GetService(“MarketplaceService”)
function MarketplaceService.ProcessReceipt(receiptinfo)
local playerProductKey = receiptinfo.PlayerId…“:”…receiptinfo.PurchaseId
local plr = game:GetService(“Players”):GetPlayerByUserId(receiptinfo.PlayerId)
local handler
for ProductId,func in pairs(Products) do
if ProductId == receiptinfo.ProductId then
handler = func break
end
end
local suc = pcall(handler,receiptinfo,plr)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
You might want to try this, another way of approaching it:
local MoneyProducts = {
[12345] = {"Money", 100},
[12346] = {"Money", 1000},
[12347] = {"Crystals", 200},
[12348] = {"Jewels", 500},
}
function AwardProduct(player, product_id)
if MoneyProducts[product_id] then --If the product is money
local MoneyType = MoneyProducts[product_id][1] --"Money", "Crystals" or "Jewels"
local MoneyAmount = MoneyProducts[product_id][2] --Amount of money to be given to the player
player.leaderstats[MoneyType].Value = player.leaderstats[MoneyType].Value + MoneyAmount
--elseif OtherProductList[product_id] then --If you have dev products other than money/crystals etc., check here.
--
end
end
First Make a Script inside ServerScriptService and get this code inside it.
local MRKP = game:GetService("MarketplaceService")
local Cash100 = YourProductIdHere
local Currency = "Money" --//identifying the currency name
MarketplaceService.ProcessReceipt = function(test)
local plr = game.Players:GetPlayerByUserId(test.PlayerId)
if test.ProductId == Cash100 then
plr.leaderstats[Currency].Value = player.leaderstats[Currency].Value + 100 --//Awarding the player what he bought
end
return Enum.ProductPurchaseDecision.PurchaseGranted --//Telling everything worked fine
end
Second
Make a Gui, put a button inside the gui and place a Local Script inside the button and paste this code inside
local MRKP = game:GetService("MarketplaceService")
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
MRKP.PromptProductPurchase(plr, YourProductIdHere)
end)