Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

PlayerHasPass getting false although the pass is owned?

Hello,

Here's the script (I know its from the wiki I copied it to make sure there were no mistakes but I have another script that I will use)

local id = 1918309
 
game.Players.PlayerAdded:connect(function(player)
    if game:GetService("GamePassService"):PlayerHasPass(player, id) then 
        print(player.Name .. " has the game pass!")
    else
        print(player.Name .. " doesn't have the game pass...")
    end
end)

1 answer

✓ Accepted answer

Hi AvionicScript. I don't know why PlayerHasPass has this bug, but it does... Which is why there's a newer and even better way to check if the user has the gamepass!

The new way is UserOwnsGamePassAsync and is used by doing game:GetService("MarketplaceService"):UserOwnsGamePassAsync(UserId, GamePassId)

The only difference between PlayerHasPass and UserOwnsGamePassAsync is that PlayerHasPass caches its result, meaning that it will continue returning the same value even if the user gets the gamepass, while UserOwnsGamePassAsync does not cache its result, making it much better.

I changed your code using this, and it seems to work perfectly fine. The only change is that you use UserId instead of the player's name, which is more reliable anyways.

local id = 1918309

game.Players.PlayerAdded:connect(function(player)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then 
        print(player.Name .. " has the game pass!")
    else
        print(player.Name .. " doesn't have the game pass...")
    end
end)

3 comments

0

Thank you so much

0

Glad to help

0

You should be putting that UserOwnsGamePassAsync in a pcall.

This discussion is preserved as it was. New answers, comments, and votes are closed.