Currency developer products?

Hey everyone!

I’m quite new to scripting and I’m working on a project that is going very well until now, so I decided I’d like to add some developer products to the game for when someone is tired of grinding so they can buy some extra amount of the currency, I’m wondering how the scripting around the dev products works, is it possible to just make a gui and make a script for if it gets clicked then [devproductID] = true and if devproductid ==true then → leaderstats.currency = leaderstats.currency + purchasedamount?

I’m not sure if it’s that simple, couldanyone tell me how it exactly works?

1 Like

On the client, you will need to prompt a dev product purchase when they click the button by doing:

game:GetService("MarketplaceService"):PromptProductPurchase(player, productID)

On the server, you will need to assign a function to the ProcessReceipt callback (This will run when a DevProduct is bought in game):

game:GetService("MarketplaceService").ProcessReceipt = function(ReceiptInfo)
    local Player = game:GetService("Players"):GetPlayerByUserId(ReceiptInfo.PlayerId)
    -- Use that Player to add Player.leaderstats currency
    return Enum.ProductPurchaseDecision.PurchaseGranted -- Needed for Roblox
end
2 Likes

Well uhmm. ProccessReceipt is not an event, but it is a callback. And if it was an event the script will error anyway with this error: Expected ‘:’ not ‘.’ Calling member function

Do I need to do the top script on a local script? and the bottom one on a server script?

Oh yeah I forgot haha. Edited the response.

Yes. The top line should be used when the player clicks a button to buy something and the bottom should run on the server.

So when the player hits the buy button i commit the top script and when that’s done i go further to the bottom one?

MarketPlaceService.ProcessReceipt is a callback. The callback is called when the player purchases a Developer Product. Its your job to check which Dev Product it is.

MarkerPlaceService also expects ProcessReceipt to return on of the Enum.PurchaseGranted enums.

xd thanks for the help, but could you try slow down a bit and explain it to me step by step?

Basically, you use the first line whenever someone clicks a button to buy a product with the arguments of the player who bought it (the LocalPlayer) and the id of the developer product you want to ask them to buy.

The code on the server only needs to be used once and it assigns a function which will run any time a developer product is bought in your game. You should read the ProcessReceipt page I linked to see all the information you are given but you can use ReceiptInfo.PlayerId and ReceiptInfo.ProductId to figure out what player (using GetPlayerByUserId) bought what developer product. Using this information, you can assign the correct reward to the correct player. E.g:

if ReceiptInfo.ProductId == 12345 then -- If they bought the product with id 12345
    Player.leaderstats.Coins += 100 -- Add 100 Coins
end

okay thanks, I’ll try that when i get back to my pc :slight_smile: