Help me with simulator script

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”)

local Products = {
[605314836]=function(receipt,player)
player.leaderstats.Money.Value = player.leaderstats.Money.Value +100
end;
[605318908]=function(receipt,player)
player.leaderstats.Money.Value = player.leaderstats.Money.Value +1000
end;
[605319209]=function(receipt,player)
player.leaderstats.Money.Value = player.leaderstats.Money.Value +3000
end;
[605321148]=function(receipt,player)
player.leaderstats.Money.Value = player.leaderstats.Money.Value +10000
end;
[605357030]=function(receipt,player)
player.leaderstats.Money.Value = player.leaderstats.Money.Value +50000
end;
[605361763]=function(receipt,player)
player.leaderstats.Money.Value = player.leaderstats.Money.Value +100000
end;

}

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

when it will not give you money, is there some unfunctional product, or the same product 1 time work and another time not

1 Like

That same product works one time and second time it does not work.

and is there some error???

Sadly, theres no errors.

30char

Could you please format your script? Now, it is almost unreadable.

1 Like

Then you aren’t returning Enum.PurchaseGranted.

1 Like

@sebi210 how do you format scripts here?

use 3 ` or put there 4 spaces before every line

When writing, click the
< / > sign.

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
1 Like

Yes, then just hook it to ProcessReceipt and you’re done.

1 Like

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)

Tell me if you need further assist

Learn More about Developer Products Here

4 Likes

Thanks to everyone who helped! I have fixed the code now.