:PromptGamePassPurchase() help

I’m trying to use :PromptGamePassPurchase() on a SurfaceGui but it won’t even print test! this is a LocalScript inside of StarterPlayerScripts!

game.Workspace.Part.SurfaceGui.TextButton.MouseButton1Up:Connect(function()
	print("test")
	MarketplaceService:PromptGamePassPurchase(LocalPlayer, GameDataModule.Gamepass_Premium)
end)
1 Like

Tip: never use game.workspace. Just use workspace, it will save you so much time


button = workspace.Part.SurfaceGui.TextButton
button.MouseButton1Up:Connect(function()
	print("test")
	MarketplaceService:PromptGamePassPurchase(LocalPlayer, GameDataModule.Gamepass_Premium)
end)

Technically there are Three valid ways to do this:

game.Workspace
workspace
game:GetService("Workspace")

None of them are the “right” way

1 Like

Ah, have you defined localplayer?


button = workspace.Part.SurfaceGui.TextButton
button.MouseButton1Up:Connect(function()
	print("test")
	MarketplaceService:PromptGamePassPurchase(game:GetService("Players").Localplayer, GameDataModule.Gamepass_Premium)
end)

I said to use workspace because it works no matter the name and it uses the least amount of characters

Edit: put s as z bruh

i used this and idk why its not working im so confused

Is your LocalScript located within the workspace?

Turns out you use Activated

https://create.roblox.com/docs/reference/engine/classes/TextButton


button = workspace.Part.SurfaceGui.TextButton
button.Activated:Connect(function()
	print("test")
	MarketplaceService:PromptGamePassPurchase(game:GetService("Players").Localplayer, GameDataModule.Gamepass_Premium)
end)

@ThinkingAIINight have you tested this?

He said it is located in StarterPlayerScripts

2 Likes

idk why its not working lol

game.Workspace.Part.SurfaceGui.TextButton.Activated:Connect(function()
	print("test")
	MarketplaceService:PromptGamePassPurchase(LocalPlayer, GameDataModule.Gamepass_Premium)
end)

it wont even print test

Are you sure you typed it in right? Lua is CaSe SeNsItIvE

1 Like

yes heres the whole script

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GameDataModule = require(ReplicatedStorage:WaitForChild("Modules").GameDataModule)

game.Workspace.Part.SurfaceGui.TextButton.Activated:Connect(function()
	print("test")
	MarketplaceService:PromptGamePassPurchase(LocalPlayer, GameDataModule.Gamepass_Premium)
end)

GameDataModule:

return {
	Gamepass_Premium = 49631462
}
1 Like

Send screenshot of all the instances (Show the part and all its descendants, the part, surfacegui, and the textbutton)
If you are on Windows use the snip tool or get it from the Microsoft store

image

image

image

Have you tried putting it in StarterCharacterScripts? Might be worth a shot

it didnt work :sob: (character limit)

1 Like

Is there any errors like infinite yield?

no there arent any errors (character limit)

Is a module script really required? @ThinkingAIINight


local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--local GameDataModule = require(ReplicatedStorage:WaitForChild("Modules").GameDataModule)

game.Workspace.Part.SurfaceGui.TextButton.Activated:Connect(function()
	print("test")
	MarketplaceService:PromptGamePassPurchase(LocalPlayer, 49631462)
end)

1 Like

Move the Surface Gui Inside The LocalScript
Next, In Your LocalScript In StarterPlayerScripts,

local MarketplaceService=game:GetService('MarketplaceService')
local Part=workspace.Part -- The Part in Workspace

local Player=game.Players.LocalPlayer
local PlayerGui=Player:WaitForChild('PlayerGui')

local SurfaceGui=script:WaitForChild('SurfaceGui') -- The Surface Gui Inside the LocalScript
local GamepassID=49631462-- Gamepass ID

SurfaceGui.Adornee=Part
SurfaceGui.TextButton.MouseButton1Up:Connect(function()
	print("Test")
	MarketplaceService:PromptGamePassPurchase(Player,GamepassID)
end)

This should work, i suggest giving it a try.

1 Like