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

Prompt a gamepass purchase using SurfaceGUI TextButton?

Script:

local MarketplaceService = game:GetService("MarketplaceService")
local ProductID = 16498748        
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptGamePassPurchase(player, ProductID)
end)

1 comment

0

I think you could add a click detector to the SurfaceGUI TextButton?

3 answers

✓ Accepted answer

I wouldn't recommend using a local script in the server. You should use a RemoteEvent to communicate from the server to client.

Server Script:

local Event = game.ReplicatedStorage.Event --RemoteEvent in ReplicatedStorage
local ClickDetector = game.Workspace.Part.ClickDetector --ClickDetector

ClickDetector.MouseClick:Connect(function(p) --Since TextButtons dont return any information about who interacted with it, we can use a click detector
	
	Event:FireClient(p) --Fire the RemoteEvent
	
end)

Local Script:

local MarketplaceService = game:GetService("MarketplaceService")
local ProductID = 16498748 
local Event = game.ReplicatedStorage.Event --RemoteEvent in ReplicatedStorage
local Player = game.Players.LocalPlayer

Event.OnClientEvent:Connect(function()
	
	MarketplaceService:PromptGamePassPurchase(Player, ProductID)
	
end)

Both scripts were fully-tested. No errors or bugs were found.

This problem happened to me before, you can try to put the script in StarterPlayersScript instead of TextButton.

In:

game.Workspace.ThePart.SurfaceGUI.TextButton

Add a Click Detector. This may help

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