So, you want to learn how to use Developer Products? Great! First off, these things are a pain in the neck if you get something wrong. If you break your script along the road, you might even be held responsible for scamming if a user reports it and you never provided the product.
Creating the Developer Product
So to start off, you will need to make the developer product. So you want to go to Develop, Places, then hit under the gear icon Configure. You would want to go to Developer Products in the Configure screen and hit Create new. Type in the name, description, price, and upload an image. Now hit create and your screen should look more like this image.
Setting Up the Developer Product in Your Game
The Local Script
The Local Script is easy to set up, you can have the product prompt show up every time the player hits a button, or every time a player respawns.
So for my example, I will be using a local script and have the script detect if the player is hitting a Gui button.
1 | script.Parent.DeveloperProductButton.MouseButton 1 Click:connect( function () |
2 | game:GetService( 'MarketplaceService' ):PromptProductPurchase( |
3 | game.Players.LocalPlayer, |
6 | Enum.CurrencyType.Default |
Due to recent site updates, CurrencyType no longer holds purpose in this function. All transactions are Robux or Free. Tickets have been discontinued.
Now that we have the developer product purchase prompt set up, let's get into the server side of these scripts.
The Server Sided Script
For this part, you will want a regular script. This is the most important step in the Developer Product process. It is up to the developer (owner of the game) to handle and record the purchase using the ProcessReceipt
function. ProcessReceipt
is a callback function, so we'll need to return a result to supposedly the ROBLOX servers eventually. What ProcessReceipt
will do is provide you with a dictionary of information. What a dictionary is, is basically a glorified table.
You will be given the following information with the ProcessReceipt
table.
PlayerId (number)
- Id of the player who made the purchase.
PlaceIdWherePruchased (number)
- Specific place where the purchase was made (I do not know the reason for this property, probably for use in Universes).
PurchaseId (string)
- Unique identifier for the purchase which should be used to prevent granting an item multiple times for one purchase (Basically a mix of random numbers and letters to prevent the scripts from granting an item more than once).
ProductId (number)
- ID of the product purchased (Great for a place with multiple Developer Products, you will need to identify what the player bought).
CurrencyType (CurrencyType Enum)
- Just used to detect how the player bought it, with Robux or Tickets.
CurrencySpent (number)
- How much of that CurrencyType the user used.
So now, let's say I want to give 1,000 points to a person in the leaderboard with my script.
01 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "ProductPurchases" ) |
03 | game:GetService( "MarketplaceService" ).ProcessReceipt = function (ReceiptInfo) |
04 | local Purchasing_Player = game.Players:GetPlayerByUserId(ReceiptInfo.PlayerId) |
07 | if ReceiptInfo.ProductId = = 123456789 then |
09 | if Purchasing_Player and Purchasing_Player:FindFirstChild( 'leaderstats' ) and Purchasing_Player.leaderstats:FindFirstChild( 'Points' ) then |
10 | Purchasing_Player.leaderstats.Points.Value = Purchasing_Player.leaderstats.Points.Value + 1000 |
15 | DataStore:IncrementAsync(ReceiptInfo.PlayerId .. '_' .. ReceiptInfo.ProductId, 1 ) |
19 | return Enum.ProductPurchaseDecision.PurchaseGranted |
Conclusion
Hopefully I made this as quick and painless as I can. If I missed anything or if you have any questions feel free to post them in the comments below. If this answered your question, then do not forget to hit the Accept Answer button.
Locked by WideSteal321, clc02, and Azarth
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?