How to make a gui that requires you to own a gamepass

Hey Developers,

I’m making a game and need help. How do I make a gui that requires you to own a gamepass and if you don’t own the gamepass, it will promt the purchase? If you can help that would be amazing.

Thanks!

You can use UserOwnsGamePassAsync() to check and see if the user owns the game pass, if they don’t then prompt them with the option to purchase it. (You’d want to use an if then an else statement)

1 Like

In the parenthesis do I put the id?

In the parameters you do UserOwnsGamePassAsync(user id of the player, game pass id)

Sample Code:

local MarketPlaceService = game:GetService("MarketPlaceService")

if MarketPlaceService:UserOwnsGamePassAsync(12345, 10492) then -- (userid, game pass id)
    -- do what you want to do since they own it
else
    -- they don't own it so prompt the game pass purchase
end
1 Like

Hi there, UndercoverAuthor!
Your question is really simple to crack!
As you said, you want a gui that requires the user to own a gamepass to show, if they don’t own it and want to open it, they’d be welcomed with a prompt purchase.
As @Notrealac0unt said, you can easily achieve this by using MarketPlaceService and it’s following functions:

  1. PromptGamePassPurchase(player, gamepassId)
  2. UserOwnsGamePassAsync(userId, gamepassId)

With knowledge of these two functions, your problems will be easily solvable! Here’s an example of code with these two:

local MPS = game:GetService("MarketPlaceService")

if MPS:UserOwnsGamePassAsync(userId, gamepassId) then
    -- whatever you want if the gamepass is owned by the player
else
    MPS:PromptGamePassPurchase(player, gamepassId)
end

I hope this helps! :slight_smile:

1 Like

When I typed ‘userId’ it said unknown global, how can i fix this

Replace userId with or declare it as:
player.UserId

1 Like

adding on to what @CherryMolotov said:

local MPS = game:GetService("MarketPlaceService")
local player = game:GetService("Players").LocalPlayer
local userId = player.UserId
local gamepassId = --put the gamepass id here

if MPS:UserOwnsGamePassAsync(userId, gamepassId) then
    -- whatever you want if the gamepass is owned by the player
else
    MPS:PromptGamePassPurchase(player, gamepassId)
end
3 Likes