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

Creating and Buying Gamepasses?

Asked by
Wkay 0
9 years ago

Hello. I'm pretty new to scripting. Though, I'm willing to start somewhere and mostly for my game. I want to make a button where my gamepass can be bought using a button in the game and give the player a sword?

0
Do I just copy and paste it into my button and replace the ID with the ID of my product? Wkay 0 — 9y

1 answer

Log in to vote
0
Answered by
Kyokamii 133
9 years ago

You would need to use PromtProductPurchase

Wiki Page; http://wiki.roblox.com/index.php?title=API:Class/MarketplaceService/PromptProductPurchase

Example;

local productId = 123456 --Id of the product you want to sell
game.Players.PlayerAdded:connect(function(player)
    Game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)  --Will offer the player to buy something when they join a game
end)

Note: You NEED to get the player, so if you want to do a GUI button, it would be this code:

--Goes in the button
local productId = 123456
script.Parent.MouseButton1Click:connect(function()
local player =  script.Parent.Parent.Parent.Parent.Parent--Get the location of the player, so you can adapt it to your settings.
game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)

Hope I helped!

Ad

Answer this question