Recently, I made a script that prompt purchases a gamepass if the player does not have it and was intended to not run if the player owned the gamepass
However, even if the player owns the gamepass it still prompt purchases it, how can I make it that it doesn’t?
local function checkGamePassAndPrompt()
-- Check if the player has the game pass
local success, hasGamePass = pcall(function()
return MarketplaceService:PlayerOwnsAsset(player, GAME_PASS_ID)
end)
if not hasGamePass then
-- Player does not have the game pass, prompt them to purchase
local success, message = pcall(function()
MarketplaceService:PromptGamePassPurchase(player, GAME_PASS_ID)
end)
end
end
Use :UserOwnsGamePassAsync instead of :PlayerOwnsAsset. The documentation for Marketplace service even explicitly states to not use :PlayerOwnsAsset for gamepasses.
Not totally sure about this without testing but, it looks like your logic is off with the 2nd if.
Also I think PlayerOwnsAsset() is deprecated.
local function checkGamePassAndPrompt(player)
local success, hasGamePass = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAME_PASS_ID)
end)
if success and not hasGamePass then
pcall(function()
MarketplaceService:PromptGamePassPurchase(player, GAME_PASS_ID)
end)
end
end
You have to use :UserOwnsGamePassAsync() instead of playerownsasset
local function checkGamePassAndPrompt()
local haspass
-- Check if the player has the game pass
local success, e = pcall(function()
haspass = MarketplaceService:UserOwnsGamePassAsync(player, GAME_PASS_ID)
end)
if not success then warn(e) return end
if not haspass then
-- Player does not have the game pass, prompt them to purchase
local success, e = pcall(function()
MarketplaceService:PromptGamePassPurchase(player, GAME_PASS_ID)
end)
end
end