How to make a Gamepass Set someones Team?

Hello there, I am in need of help to Make a Script which detects if someone owns a gamepass upon joining and then sets their Team accordingly.

So far I have looked far and wide for a souloution but have not found one.

(Basically, It checks for a gamepass with the ID of 52522 (For example) and then if the player has the gamepass they are assigned to a team called Alpha but if they dont have it they are assigned to a team called Beta.)

Please help, Thank you!
-DragonBossJ1212

2 Likes

There is never always a solution you can easily find in programming. Programming is like a puzzle, it comes together from many different pieces and you just have to figure out what those pieces are.

To avoid spoonfeeding, I’m going to give you two pieces here:

Your job now is to figure out how to put them together. Feel free to reply back if you need any help.

3 Likes

Thank you, I always like a challange. Now that I’ver recived a (Hint) This should be easier!! :smiley:

Hey, I made this script:

local id = 7403435

local Players = game:GetService("Players")

local Teams = game:GetService("Teams")

local Team = Teams.Mechanoid

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

However I’m getting this output : 03:10:24.939 - GamePassId ‘7403435’ is not of type Game Pass. Please use MarketplaceService:PlayerOwnsAsset instead.

Hang on, I’m a bad person. I gave you the deprecated method, use this one instead. Where are you finding the ID from?

The top of my Game Pass

https://www.roblox.com/game-pass/7403435/Mechanoid-Pass

The 7403435

Use the Game Explorer window in Studio and copy the ID from there after opening the Gamepass tab.

If I am not wrong, The only problem here should be that I have a bad ID. I however cannot see the Game Passes in the Game Explorer Window ._.

GamePassService is deprecated. You are meant to use MarketplaceService.UserOwnsGamePassAsync. I thought @Qxest linked an actual article but it leads to a page that, at the very top, explicitly highlights in big bold and red: “Do not use for new work.”

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local MarketplaceService = game:GetService("MarketplaceService")

local PASS_ID = 7403435

local function onPlayerAdded(player)
    -- Canonically should be pcalled
    if MarketplaceService:UserOwnsGamePassAsync(player, PASS_ID) then
        player.Team = Teams.Mechanoid
    end
end

Players.PlayerAdded:Connect(onPlayerAdded)

for _, player in ipairs(Players:GetPlayers()) do
    onPlayerAdded(player)
end

Game passes have a separate id system from all other assets. GamePassService is meant to be used with game passes that also have an id from the legacy system, though the legacy id shouldn’t be used. UserOwnsGamePassAsync is built to function with the GamePassId system in mind.

8 Likes

How do I apply this for a gui? I have posed one but I’m confused with how you can click it and if you have a game pass it changes your team