Way of telling if a product has prompted purchase?

I currently have a Cash UI, which players can purchase in game cash from. Just a minor problem I’ve discovered however is if they press A on a cash product, it prompts them to buy the product, if they press B however it close the GUI as well (because that’s how you should make B function with UI) But I find it a major inconvenience if you have to re open the UI again.

So the main question is, is there a way to tell if this product prompt is on the screen so the game knows that if the player is pressing B it is to close this, and not the actual UI

There is no event for detecting when the prompt is opened, so you’ll have to do something like:

PromptService.lua

local marketplaceService = game:GetService("MarketplaceService")
local purchasePromptIsOpen

marketplaceService.PromptGamePassPurchaseFinished:Connect(function(...)
    purchasePromptIsOpen = false
end)

marketplaceService.PromptPurchaseFinished:Connect(function(...)
    purchasePromptIsOpen = false
end)

local service = {}

function service:SetPurchasePromptOpen()
    purchasePromptIsOpen = true
end

function service:GetPurchasePromptOpen()
    return purchasePromptIsOpen
end
PurchaseScript.lua

local PromptService = require(PromptService.lua)

marketplaceService:PromptPurchase(...)
PromptService:SetPurchasePromptOpen()
UiCode.lua

local PromptService = require(PromptService.lua)

function onExitKeyPressed()
    if PromptService:GetPurchasePromptOpen() then
        -- do nothing
    else
        exitUI()
    end
end
4 Likes