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.
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
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)
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)
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)
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.
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
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.
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
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
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.