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?
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
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
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.
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