Ad
Log in to vote
0

Prompt a gamepass purchase using SurfaceGUI TextButton?

Asked by 6 days ago

Script:

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

script.Parent.MouseButton1Click:Connect(function()
    MarketplaceService:PromptGamePassPurchase(player, ProductID)
end)
0
I think you could add a click detector to the SurfaceGUI TextButton? KidMudasir7 15 — 6d

3 answers

Log in to vote
1
Answered by 4 days ago

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.

Ad
Log in to vote
0
Answered by 6 days ago

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

Log in to vote
0
Answered by 6 days ago

In:

game.Workspace.ThePart.SurfaceGUI.TextButton

Add a Click Detector. This may help

Answer this question