Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

PlayerHasPass getting false although the pass is owned?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

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)
0
Thank you so much AvionicScript 65 — 5y
0
Glad to help MythicalShade 420 — 5y
0
You should be putting that UserOwnsGamePassAsync in a pcall. Ugh_Emily 25 — 5y
Ad

Answer this question