TextButton Gamepass

I am trying to make it so when someone clicks a text button in a game they get prompted with a game pass, I have tried watching tutorials of such but all the tutorials are based around GUI’s not text buttons on a part. Please link me to a tutorial or help me to make a text part prompt a purchase.

Thanks,
George.

5 Likes

This is fairly simple using MarketplaceService.

local MarketplaceService = game:GetService("MarketplaceService")
local button = game.Workspace.Part.SurfaceGui.TextButton
local player = game.Players.LocalPlayer

button.MouseButton1Up:Connect(function()
    MarketplaceService:PromptPurchase(player, (item id))
end
5 Likes

OP is asking to how to prompt a gamepass purchase, not an asset purchase. MarketplaceService:PromptPurchase() is used to prompt a player to purchase an asset, not a gamepass.

PromptPurchase is used to prompt a player to purchase an item with the given assetId. Below is a screenshot of the purchase dialogue that appears when this function is called.

For game passes, use MarketplaceService:PromptGamePassPurchase .
(MarketplaceService:PromptPurchase() API Reference)

1 Like

This is very easy to do:

local MarketplaceService = game:GetService("MarketplaceService")
local textButton = script.Parent.SurfaceGui.TextButton
local id = 321312 -- id of your gamepass

textButton.MouseButton1Down:Connect(function(player)
   MarketplaceService:PromptGamePassPurchase(player, id)
end)

Make sure this is a script inside the part!

4 Likes

Hello! I have found a script but for some reason it only works on one of the items for sale.

1 Like

Hello! I have found a script but for some reason it only works on one of the items for sale.

Try using the one that i sent you.

1 Like

From what I recall and correct me if I am wrong, but you are not able to receive any input from UI’s in the workspace unless they are parented into your ScreenGui then set the adornee of the GUI to the part. I’ve tested this and this works for me.

Use this script as others have said, but I would disagree on using a ServerScript for something that should be handled on the client.

local Market = game:GetService("MarketplaceService")

local Player = game:GetService("Players").LocalPlayer

local Button = script.Parent
local GamepassID = 0000 -- Change

Button.Activated:Connect(function()
	Market:PromptGamePassPurchase(Player , GamepassID)
end)
4 Likes

Player’s can only interact with guis in their playergui. Put your surfacegui (or billboard gui) in startergui, and then set the Adornee property to the part it should be on.

2 Likes

MarketPlaceService has a few option for this:
:PromptGamePassPurchase() - Esclusively for gamepasses.
:PromptProductPurchase() - Exclusively for Products
:PromptPurchase() - Esclusively for the Roblox Catalog items.

Unfortunately you cannot use just 1 of these for all 3 or 2 types.
You must use the correct ones for each type.

How to prompt the purchase?

You must create the Gui though.

local plr = game.Players.LocalPlayer
local Service = game:GetService("MarketplaceService")

local Button = script.Parent

Button -- Click event here
local ID= script.Parent.TextBox.Text
Service:PromptGamePassPurchase(plr, ID)
end
3 Likes

I have a script but for some reason, I have 3 buttons and the only button it works on is one of them, they all have the correct ID’s so I do not know why.

Also I am not using a GUI I am using a button on a part??

Can you show me the Scripts and workspace please?

Script

– This is how to add a click block gamepass…

local ID = 8943096 – Change the ID

local Click = Instance.new(“ClickDetector”,game.Workspace.ClickToPromptGamepass)

local Player = game.Players.LocalPlayer

– Bloop

Click.MouseClick:Connect(function(Player)

print(‘Click was detected! GG!’)

game:GetService(“MarketplaceService”):PromptGamePassPurchase(Player, ID)

end)

1 Like

Are the text buttons name matching the script and if so try give them different names if in the same location and if you haven’t already try putting them in localscripts inside the buttons

LocalScripts don’t work in the workspace.

It is in a separate part to the buttons, like a invisible part.

Could be because your 1st parameter in the ClickDetector function doesn’t generally have one.
Normally this purchase is handled client sided. So you’d get the player like

local plr = game.Players.LocalPlayer

And then use that. That could be erroring.

1 Like

Not quite sure what you mean but the only things I can think of are: Inside the script it searches for “TextButton” There may be multiple of that in the same place or they are all named something different or you mean what the parent of the scripts are, which are the buttons. Edit: Just realised thats a statement, I am now assuming inside an invisible part inside the button there is a script, can you show us what is in workspace?

The script is not referring to a button though. Like, the button is not linked to the script. The part itself that is supposed to prompt the purchase is in another part that is transparent, it works on one of the game passes but not the others.

1 Like