These scripts are supposed to add 1 to the Value of Stage when one buys the developer product but so far it is loading to purchase but** nothing is happening after you pay**.
I have 2 scripts, this one is placed inside the player:
01 | local MarketplaceService = game:GetService( "MarketplaceService" ) |
02 | local ds = game:GetService( "DataStoreService" ):GetDataStore( "PurchaseHistory" ) |
03 | local player = game.Players.LocalPlayer |
04 | local stage = player.leaderstats:findFirstChild( "Stage" ) |
05 | CASHID = 24397415 -- Put the Developer Product ID here |
06 |
07 | MarketplaceService.ProcessReceipt = function (receiptInfo) |
08 | local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId |
09 | local numberBought = ds:IncrementAsync(playerProductKey, 1 ) |
10 | for i,v in pairs (game.Players:GetChildren()) do |
11 | if v.userId = = receiptInfo.PlayerId then |
12 | if receiptInfo.ProductId = = CASHID then |
13 |
14 | if stage.Value < 25 then |
15 | stage.Value = stage.Value + 1 |
This one is placed in the button of the GUI
1 | local productId = 24397415 |
2 | local player = game.Players.LocalPlayer |
3 |
4 | script.Parent.MouseButton 1 Click:connect( function () |
5 | game:GetService( "MarketplaceService" ):PromptProductPurchase(player, productId) |
6 | end ) |
The problem is that you are using a LocalScript for handling the purchase, where you should be using a normal Script.
What you need to do is put the code into a normal script, get rid of the player and stage variables and then use the player found in the for loop (reference by the variable 'v' without quotes) to increase their stage value.
Also, you need to return PurchaseGranted inside your purchase handling function, otherwise you will not receive any money from ROBLOX.
Overall, your final script should look like this:
01 | local MarketplaceService = game:GetService( "MarketplaceService" ) |
02 | local ds = game:GetService( "DataStoreService" ):GetDataStore( "PurchaseHistory" ) |
03 |
04 | CASHID = 24397415 -- Put the Developer Product ID here |
05 |
06 | MarketplaceService.ProcessReceipt = function (receiptInfo) |
07 | local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId |
08 | local numberBought = ds:IncrementAsync(playerProductKey, 1 ) |
09 | for i,v in pairs (game.Players:GetPlayers()) do |
10 | if v.userId = = receiptInfo.PlayerId then |
11 | if receiptInfo.ProductId = = CASHID then |
12 | local stats = v:WaitForChild( "leaderstats" ) --Yields the script until leaderstats becomes available. |
13 | local stage = stats:WaitForChild( "Stage" ) --Same as above, but waits for the stage value in leaderstats. |
14 | local char = v.Character --Referencing the character. |
15 | if stage.Value < 25 then |
I hope my answer helped you. If it did, be sure to accept it.