How to prompt the PromptPremiumPurchase by clicking on a gui?

How to prompt the PromptPremiumPurchase function by clicking on a gui(I mean a textbutton)? It’s probably easy… Please don’t send me a devhub article, I read that already. Thanks!

Well you should really watch a tutorial or search on the devforum but tbh a devhub article is your best bet. Try doing some research first before just coming and posting asking for a script.

Use this one line here to prompt the purchase

MarketplaceService:PromptPremiumPurchase(player)

You would hook that up to a text button eg

local marketplace = game:GetService("MarketPlaceService")
local player = game.Players.LocalPlayer
local textButton = -- path to your button

textButton.MouseButton1Click:Connect(function() 
     marketplace:PromptPremiumPurchase(player)
end)

Actually, my only problem is to mention the player. I always get the error “First argument to the PromptPremiumPurchase must be a player”.

It would be better to also check if the player is alreayd premium before prompting because it would prompt them an error message. If it’s not wanted, then it would be best to check their MembershipType as well

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

local player = Players.LocalPlayer

local gui = script.Parent --Assuming localscript is in the textbutton

gui.MouseButton1Down:Connect(function()
	if player.MembershipType == Enum.MembershipType.Premium then
		return
	end
	MarketplaceService:PromptPremiumPurchase(player)
end)
2 Likes

the player has to be a player object im assuming to you cant put there name