Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make a GUI that let's you buy a developer product?

Asked by 7 years ago
Edited 7 years ago

So, I'm working on an obby and I'm trying to make a skip stage GUI. But I searched it up on google and the model I got didn't work... I don't want to add teams, though. Here is the script I tried:

local productId = 47185810 -- Change to the ID of your developer product.
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)
That script was in the GUI.
stat = "Stage" -- Change to the stat's name.
award = 1 -- Change to the ammount of stat to award.
MarketplaceService = Game:GetService("MarketplaceService")
MarketplaceService.ProcessReceipt = function(receiptInfo)
players = game.Players:GetPlayers()
for i=1,#players do
if players[i].userId == receiptInfo.PlayerId then
players[i].leaderstats[stat].Value = players[i].leaderstats[stat].Value+award
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted 
end

This was in the serverscriptservice.

0
lol minikitkat 687 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

I got slightly confused but now I got it! Read from lines 1 to 5 for the LocalScript. Then for the rest (7 to end), it is the Server Script.

Okay, firstly, userId is now deprecated, so use UserId instead. Next, I would rather use for i, v in pairs(players) do rather than for i = 1, #players do when iterating over players, in my opinion. Finally, when using variables, make them local so the script will run better. So... let me edit your script a little bit:

LocalScript:

local productId = 47185810 -- Change to the ID of your developer product.
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)

Server Script:

local id = 47185810
local stat = "Stage" -- Change to the stat's name. Make the variables LOCAL so the script will run better.
local award = 1 -- Change to the ammount of stat to award.
MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.ProcessReceipt = function(receiptInfo)
    local players = game.Players:GetPlayers()
    for _, player in pairs(players) do -- player = v; _ = i when not needed.
        if player.UserId == receiptInfo.PlayerId and receiptInfo.ProductId == id then -- Make sure it's the product the player brought
            player.leaderstats:WaitForChild(stat).Value = player.leaderstats:WaitForChild(stat).Value + award
        end
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted 
end

Any questions? Leave them in the comments! Thanks and I hope this will help. :)

0
Whenever I try buying it, I get this. http://prntscr.com/dq3rpp OreoPatton 8 — 7y
0
check the developer console (press F9) and see if any error messages are in there. starlebVerse 685 — 7y
0
this is really something beyond my control! I don't see any errors... I don't know what to do... Try publishing the place in studio again and rejoin the server. starlebVerse 685 — 7y
Ad

Answer this question