Developer Product gui not working

I’m making a gui that, when you click it, displays a gamepass. Simple. However, when I run the game, it prompts the purchase. When I click the gui to display the gamepass, it returns an “Attempt to call nil value” error. I’ve placed this script inside StarterPlayerScripts, and it is a LocalScript.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Gui = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')
local Screen = Gui:WaitForChild("ScreenGui")
local Player = Players.LocalPlayer

local ProductID = (1130296003)

print(Players.LocalPlayer)

function promptPurchase()
	MarketplaceService:PromptProductPurchase(Player, ProductID)
end

Screen.TextButton.MouseButton1Click:Connect(promptPurchase())
1 Like

Try removing the parentheses in the id

Hey there!

So basically, when you add a () to the end of a function, you’re executing it,
but what you need to do is connect the actual function variable. Basically, in the final line,
you’re connecting nil because at the end, theres a () so ROBLOX thinks your connecting
what the function is returning (which is nothing, since there’s no return statement.

To fix this, the last line in the code you provided should be:

Screen.TextButton.MouseButton1Click:Connect(promptPurchase)

(Without the “()” at the end so it is connecting the actual function instead of what the executed function returns)

Hope this helps! :smiley:

1 Like

Screen.TextButton.MouseButton1Click:Connect(promptPurchase())

Remove () after promptPurchase.

1 Like