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)```
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
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
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:
Put a localscript into StarterPlayerScripts
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)
Set gamepassId to your gamepass id
Set textButton to the path where your textButton is
And hopefully that works! Let me know if you have any questions.
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.