Check if Player has Gamepass

I’m using the wiki to figure out how to determine if a player has a game pass: https://developer.roblox.com/api-reference/function/GamePassService/PlayerHasPass

I’m trying to check to see if a player has a game pass, and this isn’t working.

I’ve also tried

local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, player, 6508305)
if doesPlayerOwnAsset then
    --idk something
end

which worked for doing badges, but I’m at a loss.

11 Likes

Right on the page: “This function will not work with new game passes, use MarketplaceService/UserOwnsGamePassAsync instead.”

11 Likes

UserOwnsGamePassAsync would work for this.

local MarketPlaceService = game:GetService"MarketPlaceService"
local function ownsgamepass(userid,gamepassid)
    local s,res = pcall(MarketPlaceService.UserOwnsGamePassAsync,MarketPlaceService,userid,gamepassid)
    if not s then
        res = false
    end
    return res
end
15 Likes

If you actually take a look at the PlayerHasPass Wiki page, it says that the function has been deprecated, meaning that it’s no longer suitable for current works. This function have the parameters userId and assetId. It still works for Game Passes that have been created in the past, but not now.

In the other, the replacement is to use the UserOwnsGamePassAsync function. When using this function, the parameters will be userId and gamePassId. The gamepassId you can still retrieve it through the URL.

4 Likes

Read the page? There’s a giant header right there making mention that you should use a different function.

Not what this category is for.

5 Likes

how would you get the return? like in order to read if it’s true or false

1 Like

The link(s) above should have covered this for you but, UserOwnsGamePassAsync returns whether the player has bought a Game-pass or not

UserOwnsGamePassAsync returns true if the Player with the given UserId owns the game pass with the given game pass ID (not to be confused with asset ID).

Example:

local MarketPlaceService = game:GetService("MarketPlaceService ")

local PlayerBoughtThisGamePass =  MarketPlaceService.UserOwnsGamePassAsync(Userid, GamePassiD)

if PlayerBoughtThisGamePass then
  print("Player Has Bought This GamePass")
end

Have a great day or night!

22 Likes

So, I’m having a similar issue. That’s why I’m allowed to bump, lol.

I have only been able to find stuff like “when the player buys a pass run the function”, this helps.

I think @MayorGnarwhal probably should mark it as a solution, BUT,

In this line:

You should (in modern roblox at least, idk if that worked at once
should do this:

("MarketplaceService")

Hope this helps anyone looking through this stuff!

4 Likes

Should be there player.userId on line 3rd

1 Like

I am new to scripting and devfourm

Am not sure if this will work

Put this script in ServerScriptService:
local GamePassID = --Gamepass ID

local MarketService = game:GetService(“MarketplaceService”)

game.Players.PlayerAdded:Connect(function(Plr)
local PlayerHasGamePass = MarketService:UserOwnsGamePassAsync(Plr.UserId, GamePassID)
if PlayerHasGamePass then
–Code
end
end)

1 Like

Isn’t is

local GamePassID = 'Gamepass code'

local MarketService = game:GetService(“MarketplaceService”)

game.Players.PlayerAdded:Connect(function(Plr)
local PlayerHasGamePass = MarketService:UserOwnsGamePassAsync(Plr.UserId, GamePassID)
if PlayerHasGamePass == true then
--code
elseif PlayerHasGamePass == false then
--code
end 
end)

As I am pretty sure it would run the code if it successfully ran the Check and wouldn’t run if it returns true.

2 Likes

Or I would run it as

local GamePassID = 'Gamepass Code'--Gamepass ID

local MarketService = game:GetService(“MarketplaceService”)

local function CheckForGamepass(Plr)
local PlayerHasGamePass = MarketService:UserOwnsGamePassAsync(Plr.UserId, GamePassID)
if PlayerHasGamepass == true then
--code
elseif PlayerHasGamepass == false then
--code
    end
end

game.Players.PlayerAdded:Connect(CheckForGamepass)
1 Like

I tried this script and it worked

It didn’t work for you??

1 Like

Nevermind. I read the function wrong. I haven’t tried it. I read it basically as Check if the user owns it not that they actually own it. :slight_smile:

1 Like