How to make a team button (gui) that only people with a gamepass can click and be teamed?

Hey, I ain’t that much of a scripter and youtube isn’t helping me so, I have to ask you guys, so, I need a script for a team button that is only available to gamepass owners, I already have the GUI ready I just need the script to make it gamepass only.

-- local script in button
local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.TeamChange:FireClient(Player)
end)
-- server script in server script service
local Teams = game:GetServie("Teams")
local Team1 = Instance.new("Team", Teams)
Team1.BrickColor = BrickColor.new("YourBrickColor")
Team1.Name = "YourTeamName"
game.ReplicatedStorage.TeamChange.OnClientEvent:Connect(function(player)
    player.Team = Team
end)

Let me know if an error happens

1 Like

Thank you, we are about to test it, i’ll inform you if it works or no.

2 Likes

Where do we put the gamepass ID?

1 Like

what do you mean??? Are you ranking the player by seeing what rank they are in your group?

2 Likes

Well no, we want it to be like a button that teams you into an existing team but only people with the the selected gamepass can press it and get teamed.

3 Likes

local GamepassId = "Gamepassidhere"

local MarketplaceService= game:GetService("MarketplaceService")

if MarketplaceService:UserOwnsGamePassAsync(userId, GamepassId) then
--code here
end

3 Likes

Sorry for the late response, let me try it.

1 Like

I am also having a similar situation, so I searched this up and tested this script. But it is getting confused with the “userId” part. It says “W001: Unknown Global”. I understand I am quite a bit late, but I am having a similar issue and I am wondering how to fix this. Should “userId” be a variable? Or what?

2 Likes

try

player.UserId

instead of

player.userId

oh noooo, the userid is supposed to be the players userid i put userId there just so you know to put the players user id
like this

local GamepassId = "Gamepassidhere"

local MarketplaceService= game:GetService("MarketplaceService")

if MarketplaceService:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, GamepassId) then
--code here
end
3 Likes

Okay thank you so much. I really needed that!

1 Like