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

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

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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)
1
This wouldn't work anymore, PlayerHasPass is depreciated, easy fix though, just change it to the MarketplaceService and put UserOwnsGamePassAsync Carvizal 25 — 5y
Ad

Answer this question