Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Creating and Buying Gamepasses?

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?

1 comment

0

Do I just copy and paste it into my button and replace the ID with the ID of my product?

1 answer

✓ Accepted answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.