Trying to prompt developer product purchase but keep getting output error

I want to make it so that when a player clicks on a TextButton under SurfaceGui that it prompts the purchase of a developer product
I keep getting the same error in Output:
MarketplaceService:PromptProductPurchase() player should be of type Player

I don’t know why this keeps happening and have looked at multiple topics.
This is the script I’m using.

local Player = game:GetService('Players').LocalPlayer
local MarketplaceService = game:GetService('MarketplaceService')

script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(Player,1583342669)
end)

The solution is probably simple.

Take a look at this:

It appears a tad bit confusing.

Ok… maybe this post will help you. It’s not as confusing:

Let me just explain this to you…

You need to put the SurfaceGui inside of a ScreenGui. The ScreenGui needs to be inside of the StarterGui. Then set your SurfaceGui Adornee to the part you want the SurfaceGui to be on. Then put a LocalScript in your TextLabel.

Put this in your LocalScript:

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

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

I changed the script’s RunContext to “Client” which should be the same as a LocalScript and it worked. Thanks for the help!

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