Why won't the script prompt the purchase?

Hello,
I am trying to make a gui that when you click prompts a purchase to buy a shirt. When I click it gives me an error saying “[MarketplaceService:PromptPurchase() player should be of type Player, but is of type nil”. Here is the code:

local itemID = 5668245964


script.Parent.MouseButton1Click:Connect(function(p)
	game:GetService("MarketplaceService"):PromptPurchase(p,itemID)
end)
2 Likes

MouseButton1Click does not pass the player as an argument.

1 Like

Define the player by using local player = game.Players.LocalPlayer and then say:

local itemID = 5668245964
local player = game.Players.LocalPlayer


script.Parent.MouseButton1Click:Connect(function()
	game:GetService("MarketplaceService"):PromptPurchase(player,itemID)
end)
3 Likes

It still gives me the same error, it says PromptPurchase() player should be of type player but is of type nil

Ok first make sure that your gamepass id is valid. If it is a gamepass, I recommend using PromptGamePassPurchase. Also this only works if it is a local script.

Oh my god I forgot to make it a local script lol.

1 Like