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

How to check if a player has a gamepass? (SOLVED)

Hey, I'm making a game and I want to know how to check if they have the gamepass to activate a function. Does it require an if statement? Is this suppose to be in a local script?

1 answer

✓ Accepted answer

Here is a place to help you http://wiki.roblox.com/index.php?title=Game_Pass

here's some code of the wiki and a little edited by me

local passId = 0000000 -- change this to your game pass ID.
 
function isAuthenticated(player) -- checks to see if the player owns your pass 
    return game:GetService("GamePassService"):PlayerHasPass(player, passId) -- this method will check to see if player has the pass from the passId
end
 
function Start(plr)
	print(plr.Name .. " has bought the game pass with id " .. passId)
end

game.Players.PlayerAdded:connect(function(plr)
    if isAuthenticated(plr) then -- checks to see if player is authenticaded
        Start(plr) -- activate function
    end
end)

2 comments

1

This wouldn't work anymore, PlayerHasPass is depreciated, easy fix though, just change it to the MarketplaceService and put UserOwnsGamePassAsync

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