How to make a button visible when a player first purchases a gamepass?

I have two different gamepasses that need to be purchased in order to use. The button that it is shown to non-GP members are buttons that say “Purchase Gamepass!” I was trying to make a code in which made it so that it would make the “Purchase Gamepass!” button invisible and make the “unlocked” button visible.

local MarketplaceService = game:GetService("MarketplaceService")

local MainFrame = script.Parent.Frame
local player = game.Players.LocalPlayer

local GP_cr = MainFrame.customRadio_purchase
local GP_bb = MainFrame.boomBox_purchase

local cr_bt = MainFrame.boomBox
local bb_bt = MainFrame.customRadio

local ID_cr = 14536083 -- custom radio gamepass 10$
local ID_bb = 14537695 -- boombox gamepass 500$

-- BOOMBOX GAMEPASS
GP_bb.MouseButton1Down:Connect(function()
	local sucess, message = pcall(function()
		hasPass4 = MarketplaceService:UserOwnsGamePassAsync(player.UserId, ID_bb)
	end)

	if hasPass4 then
		print("Player already has BOOMBOX gamepass")
		GP_bb.visible = false
		bb_bt.visible = true
	else
		MarketplaceService:PromptGamePassPurchase(player, ID_bb)
	end
end)


-- CUSTOM RADIO GAMEPASS
GP_cr.MouseButton1Down:Connect(function()
	local sucess, message = pcall(function()
		hasPass5 = MarketplaceService:UserOwnsGamePassAsync(player.UserId, ID_cr)
	end)

	if hasPass5 then
		print("Player already has CUSTOM RADIO gamepass")
		GP_cr.visible = false
		cr_bt.visible = true
	else
		MarketplaceService:PromptGamePassPurchase(player, ID_cr)
	end
end)

Edit: Problem: Basically, whenever the player purchases the gamepass, the buttons don’t change. You have to leave the game and come back to see the buttons change.

Any help is greatly appreciated, thanks!

1 Like

What is your issue? You should explain as we cannot really help you without knowing what to look for.

3 Likes

Right, my bad. Basically, whenever the player purchases the gamepass, the buttons don’t change. You have to leave the game and come back to see the buttons change.

1 Like

You need up setup a MarketplaceService | Roblox Creator Documentation function, which detects game pass purchases in-game.