PromptPurchase from SurfaceGui

  1. What do you want to achieve?
    A PromptPurchase from a TextButton inside of a SurfaceGui.

  2. What is the issue?
    It doesn’t seem to be working, I have tried fixing it myself but had no luck.

  3. What solutions have you tried so far?
    I have looked on the DevForum and YouTube and have found nothing.

Here is the script:

local productId = 1331518806
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)

image (6)

LocalScript's cannot be used inside SurfaceGui's

Try Creating a ScreenGui, Put the SurfaceGui inside it, and then Adornee it to the Part

Screenshot (88)

Screenshot (87)

When Adorned (NOT Parented), Should Looked like this:

After that, You should be able to click it with a LocalScript

3 Likes
local MarketplaceService = game:GetService("MarketplaceService")
local ID = 1331518806

script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer, ID)
end)

LocalScripts don’t work if they were originally parented to workspace. You would either have to move the SurfaceGui to StarterGui and change it’s Adornee property to the InstantPass.Screen part, or parent the LocalScript in recommendably StarterPlayerScripts and just reference the Buy button and detect it’s MouseButton1Click event.

3 Likes

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