@MayorGnarwhal (Gnarwhal) posted a new topic, subject "Check if Player has Gamepass". It read:

   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
    [code] 
        local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, player, 6508305)
        if doesPlayerOwnAsset then
            --idk something
        end
        
    [/code]
    
    which worked for doing badges, but I'm at a loss.
      *[Discord]: Sezei#3061

So @rogchamp (pasta) replied

    Right on the page: “This function will not work with new game passes, use `MarketplaceService/UserOwnsGamePassAsync` instead.”
      *[Discord]: Sezei#3061

To which @Halalaluyafail3 (FindFirstChild) replied

    UserOwnsGamePassAsync would work for this.
    [code] 
        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
        
    [/code]
      *[Discord]: Sezei#3061

@slothfulGuy (slothfulGuy) replied

    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.
      *[Discord]: Sezei#3061

@colbert2677 (colbert2677) replied

    MayorNarwhal:
    
    > Alright the Wiki is making me angry because it seems to be feeding me lies.
    
    Read the page? There's a giant header right there making mention that you should use a different function.
    
    MayorNarwhal:
    
    > (as in I want to be spoon feed the answer. Many thanks)
    
    Not what this category is for.
      *[Discord]: Sezei#3061

@mocrews1 (jhene) replied

    how would you get the return? like in order to read if it's true or false
      *[Discord]: Sezei#3061

@OnlyJaycbee (Jaycbee) replied

    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:
    [code] 
        local MarketPlaceService = game:GetService("MarketPlaceService ")
        
        local PlayerBoughtThisGamePass =  MarketPlaceService.UserOwnsGamePassAsync(Userid, GamePassiD)
        
        if PlayerBoughtThisGamePass then
          print("Player Has Bought This GamePass")
        end
        
    [/code]
    
    Have a great day or night!
      *[Discord]: Sezei#3061

Then @DarkPixlz (Florida_Man) said

    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:
    
    Halalaluyafail3:
    
    > `"MarketPlaceService"`
    
    You should (in modern roblox at least, idk if that worked at once  
    should do this:
    [code] 
        ("MarketplaceService")
        
    [/code]
    
    Hope this helps anyone looking through this stuff!
      *[Discord]: Sezei#3061

@SecretGameCreatorDev (Jants) replied

    Should be there player.userId on line 3rd
      *[Discord]: Sezei#3061

Then @khalid20197PC (khalid20197PC) said

    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)
      *[Discord]: Sezei#3061

@daffyjacks3 (Daffy_ThePenguin) replied

    Isn't is
    [code] 
        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)
        
    [/code]
    
    As I am pretty sure it would run the code if it successfully ran the Check and wouldn't run if it returns true.
      *[Discord]: Sezei#3061

So @daffyjacks3 (Daffy_ThePenguin) replied

    Or I would run it as
    [code] 
        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)
        
    [/code]
      *[Discord]: Sezei#3061

To which @khalid20197PC (khalid20197PC) replied

    I tried this script and it worked
    
    It didn't work for you??
      *[Discord]: Sezei#3061

Then @daffyjacks3 (Daffy_ThePenguin) said

    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. 
      *[Discord]: Sezei#3061


{'source': 'discourse', 'url': 'https://devforum.roblox.com/t/check-if-player-has-gamepass/287289', 'title': 'Check if Player has Gamepass', 'views': 25790, 'has_accepted_answer': False, 'word_count': 915, 'like_count': 90, 'reply_count': 8, 'participant_count': 11, 'posts': 14, 'tags': '', 'author': '@MayorGnarwhal (Gnarwhal)', 'participants': '@MayorGnarwhal (Gnarwhal), @rogchamp (pasta), @Halalaluyafail3 (FindFirstChild), @slothfulGuy (slothfulGuy), @colbert2677 (colbert2677), @mocrews1 (jhene), @OnlyJaycbee (Jaycbee), @DarkPixlz (Florida_Man), @SecretGameCreatorDev (Jants), @khalid20197PC (khalid20197PC), @daffyjacks3 (Daffy_ThePenguin)', 'image_url': [None], 'created_at': '2019-06-02T00:25:34.710Z', 'last_posted_at': '2022-03-07T20:30:15.803Z'}