SurfaceGui Purchase Issue

I have this surface gui with buttons on it and it seems to not be working. The output says these errors,"
MarketplaceService:PromptProductPurchase() player should be of type Player, but is of type Players
MouseButton1Click is not a valid member of TextLabel “Players.Itsjacobiward.PlayerGui.ThanksMessage.TextLabel.TextLabel”
Workspace.Tithes & Offering.SurfaceGui.Frame.TextButton.Purchase:8: attempt to index nil with ‘PlayerId’

Here’s my code for the things.

This is the Text button script
"local MarketplaceService = game:GetService(“MarketplaceService”)
local players = game:GetService(“Players”)

local productID = 1209398991

local function processReceipt (receiptInfo)

local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
	-- The player proably left the game
	-- If they  come back, the callback will be called again
		return Enum.ProductPurchaseDecision.NotProcessedYet

if player then
	-- What happens when purchased
	game.StarterGui.ThanksMessage.Enabled = true
	print(player.Name.. " just bought " .. receiptInfo.ProductId)

return Enum.ProductPurchaseDecision.PurchaseGranted


– Set callback
MarketplaceService.ProcessReceipt = processReceipt()"

Here’s the local script

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

local productID = 1209398991
local player = game.Players.LocalPlayer

MarketplaceService:PromptProductPurchase(Players, productID)"

Few things:

Should be MarketplaceService.ProcessReceipt = processReceipt, you have an extra pair of parentheses which is going to cause an issue where you’re trying to assign a non-function value to the callback

2- The reason it’s giving that error is because you’re trying to pass the players service to the prompt product purchase func, to fix it:

local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)

local productID = 1209398991
local player = Players.LocalPlayer

MarketplaceService:PromptProductPurchase(player, productID)

Ok, so that’s been fixed, how do I fix the MouseButton1 issue do I add a click detector?

No, you should be able to reference the button as normal with the MouseButton1Click event.

I’m still getting the error saying that it’s not a valid member of TextLabel.

Switch it to a text button, you need a button instead of a label

It is a text button, do I need to move scripts?

I’m not sure, you should be referencing a textbutton though, not a textlabel

Ok I think I figured it out I saw that it was a label and I got confused, so yeah u are right.

1 Like

Nope, still nothing, I’m not sure why it won’t work. I keep getting the prompt as soon as I join.

Can you send the code you have rn?

script.Parent.Parent.Visible = false

You have to prompt the player’s purchase in the function

Still nothing happened, can u tell me how u would do it and have it set up

I watched this video to do it

And and what I want to happen is when the player buys the donation thing they get a gui saying thanks with a typewriter effect and it has a X button


You’re trying to prompt the entire Players service instead of the player.

This is the correct way to prompt a purchase:

MarketplaceService:PromptProductPurchase(player, productID)

I have that but I still get an error.

What does the error say?

Reading what the error says usually helps, by the way…

I’m not getting a error anymore but I do have a issue when I start the game I get promoted to purchase and when I attempt to press the button they don’t work

    script.Parent.Parent.Visible = false
    MarketplaceService:PromptProductPurchase(player, productID)