Open gamepass prompt over an SurfaceGui TextButton

Hello guys!

I just Want to create an Gamepass Prompt opens when You click on an SurfaceGui Textbutton, but It is not working? Is it beacuse im using An Local Script?

This is the script!


local function onButtonActivated()
	print("Button activated!")
	local ID = 13684438 
	script.Parent.ClickDetector:Connect(function()
		game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,ID)
	end)


end

button.Activated:Connect(onButtonActivated)```
1 Like

You don’t need the ‘script.Parent.ClickDetector’ bit, just put the code that would run in there under the ‘onButtonActivate’ function.

1 Like

Where is the script? if it is a descendant of the workspace, but not of the character, or from another place not related to the player, it will not work

It is In the TextButton Of the SurfaceGui And The SurfaceGui Is in a Part from the Workspace!

Move the LocalScript to StarterPlayerScripts and change your code to this

local ClickDetector =  --location
local button = --location
button.Activated:Connect(function()
	print("Button activated!")
	local ID = 13684438
	ClickDetector.MouseClick:Connect(function(Player)
		if Player ~= game:GetService("Players").LocalPlayer then   return   end
		game:GetService("MarketplaceService"):PromptGamePassPurchase(Player,ID)
	end)
end)

replace --location by the location of the object, I don’t know, workspace.Part.ClickDetector for example

Still Not Working? Maybe it is beacuse the ClickDetector Is not working, when i hover over the Part it dont show the CursorIcon of the ClickDetector.

gui buttons dont need clickdetectors you need to make use of MouseButton1Clicked

Hey! For this, you don’t need a click detector (Although one can be used). If you’re wanting to do it by a player clicking on a text button then you need:

  1. Put a localscript into StarterPlayerScripts
  2. Put this code in it:
local mps = game:GetService("MarketplaceService")
local gamepassId = 0
local player = game.Players.LocalPlayer
local textButton = game.Workspace.Part.SurfaceGui.TextButton

textButton.MouseButton1Click:Connect(function()
	mps:PromptGamePassPurchase(player, gamepassId)
end)
  1. Set gamepassId to your gamepass id
  2. Set textButton to the path where your textButton is

And hopefully that works! Let me know if you have any questions.

1 Like

Put the local script in a service that supports it, and not in a descendant of the workspace. You might have to rewrite the path in the event function for that.
Also, use:

ClickDetector.MouseClick:Connect(function()

instead of just ClickDetector:Connect
Hope this helps!

You can’t embed a prompt gamepass purchase onto a SurfaceGui but you can have a SurfaceGui which contains a button that when clicked prompts a gamepass purchase in the normal way.