Script:
1 | local MarketplaceService = game:GetService( "MarketplaceService" ) |
2 | local ProductID = 16498748 |
3 | local player = game.Players.LocalPlayer |
4 |
5 | script.Parent.MouseButton 1 Click:Connect( function () |
6 | MarketplaceService:PromptGamePassPurchase(player, ProductID) |
7 | end ) |
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:
1 | local Event = game.ReplicatedStorage.Event --RemoteEvent in ReplicatedStorage |
2 | local ClickDetector = game.Workspace.Part.ClickDetector --ClickDetector |
3 |
4 | ClickDetector.MouseClick:Connect( function (p) --Since TextButtons dont return any information about who interacted with it, we can use a click detector |
5 |
6 | Event:FireClient(p) --Fire the RemoteEvent |
7 |
8 | end ) |
Local Script:
01 | local MarketplaceService = game:GetService( "MarketplaceService" ) |
02 | local ProductID = 16498748 |
03 | local Event = game.ReplicatedStorage.Event --RemoteEvent in ReplicatedStorage |
04 | local Player = game.Players.LocalPlayer |
05 |
06 | Event.OnClientEvent:Connect( function () |
07 |
08 | MarketplaceService:PromptGamePassPurchase(Player, ProductID) |
09 |
10 | 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:
1 | game.Workspace.ThePart.SurfaceGUI.TextButton |
Add a Click Detector. This may help