Gamepass Purchase Script doesn't work

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Fix the script
  2. What is the issue? Include screenshots / videos if possible!
    Game Pass script not working
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I asked the studio assistant and other developers.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local MarketplaceService = game:GetService("MarketplaceService")

local Player = game.Players.LocalPlayer
local GamepassID = 134311828

script.Parent.MouseButton1Click:Connect(function()
    MarketplaceService:PromptGamePassPurchase(Player, GamepassID)
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

are there any errors in console?

1 Like

Prompt Purchases must be made on the Server, you would need RemoteEvents for that

2 Likes

that is incorrect, you can call promptgamepasspurchase from a localscript. im assuming either
1 - the id is incorrect
2 - the parent of this script isnt in screengui

3 Likes

Ok,a thing is you need another function to call it

1 Like

Oh.Should the script be in ScreenGUI?

where is the button located? is it anywhere inside a screengui?

It locates in SurfaceGUI.TextButton

1 Like

By the looks of it, the script is directly parented under a GuiObject, specifically one with button functionalities.

Does the script work if I alter it like this?

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local GamepassID = 134311828

script.Parent.MouseButton1Click:Connect(function()
    MarketplaceService:PromptGamePassPurchase(Player, GamepassID)
end)

Additionally, can you check that the script’s context is actually in client and not server? You can see it through Properties window.

1 Like

if its in a surfacegui, then you need to set the parent of the surfacegui in startergui. then set the adornee (SurfaceGUI.Adornee) to the part its under

Someone correct me if I’m wrong, but I’m 90% sure a LocalScript won’t run if it is a descendant of the workspace (excluding the player’s character).

Change it to a server script and prompt with that, or use a RemoteEvent to communicate to the client to prompt it, or just get the button in a LocalScript under StarterPlayerScripts and prompt it there.

1 Like

as much as this would work, a way better way is to:

  1. Move the SurfaceGui into StarterGui
  2. Set the Adornee (SurfaceGui.Adornee) to the part you want it to display on

Then this code would work normally using a LocalScript and a TextButton.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.