I have two buttons, one that says “Purchase Gamepass!” and the other one is the actual Gamepass button that does stuff. I’m trying to make it so that the buttons immediately change after a player purchases the gamepass., and doesn’t have to rejoin the game for it to appear.
Is there a better way to do this? I kinda don’t know what I’m doing here.
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 == true then
print("Player already has BOOMBOX gamepass")
GP_bb.visible = false
bb_bt.visible = true
else
MarketplaceService:PromptGamePassPurchase(player, ID_bb)
end
end)
MarketplaceService.PromptBundlePurchaseFinished:Connect(function(player, ID_bb, was_purchased)
GP_bb.visible = false
bb_bt.visible = true
end)
-- CUSTOM RADIO GAMEPASS
GP_cr.MouseButton1Down:Connect(function()
local sucess, message = pcall(function()
hasPass5 = MarketplaceService:UserOwnsGamePassAsync(player.UserId, ID_cr)
end)
if hasPass5 == true then
print("Player already has CUSTOM RADIO gamepass")
GP_cr.visible = false
cr_bt.visible = true
else
MarketplaceService:PromptGamePassPurchase(player, ID_cr)
end
end)
MarketplaceService.PromptBundlePurchaseFinished:Connect(function(player, ID_cr, was_purchased)
GP_cr.visible = false
cr_bt.visible = true
end)
Any help is greatly appreciated, thanks!
Edit: Minor code edit