Team Gamepass Script

Im making a script that if a player haves the gamepass. It should move the player to :gem:| Vip Team

Should this script work or not? I can’t test it thats why im asking
Schermafbeelding 2021-05-15 205628 Schermafbeelding 2021-05-15 205642 Schermafbeelding 2021-05-15 205806
Schermafbeelding 2021-05-15 210433

Your not supposed to have a ‘.’ at line 7. Try removing that. (Between ‘Teams’ and [“:gem:| Vip”])

Edit: Also, try using MarketPlaceService to check if the player has the gamepass.

ok thanks man but if i delete that should it work?

GamePassService is deprecated. Since you have something, I can help you now.

local MPS = game:GetService("MarketplaceService")
local gamepass = script:FindFirstChild("GamePassId")
local teams = game:GetService("Teams")

game.Players.PlayerAdded:Connect(function()
   if MPS:UserOwnsGamePassAsync(player.UserId,gamepass.Value) then
      player.Team = Teams["TEAMNAME"]
   end
end)

The script you had wouldve worked about 2 years ago. And while technically it will still work its very complicated to get it to work, you should be using MarkeplaceService

1 Like
  1. PlayerHasPass is deprecated.
  2. On line 7, remove the dot operator as it will error otherwise since you’re trying to index the team.
  3. You should loop through every player when the script runs, in case of any delays.
  4. There’s no need for a WaitForChild, it will exist once the script runs.
local Players = game:GetService('Players')
local MarketplaceService = game:GetService('MarketplaceService')
local Teams = game:GetService('Teams')
local Team = Teams['TeamName']
local GamePassId = script.GamePassId -- GamePassId will already exist on the server, no need for WaitForChild here.


local function PlayerAdded(Player)
	local OwnsGamePass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamePassId.Value)
	if OwnsGamePass then
		Player.Team = Team
	end
end


-- Loop through existing players. 
local GetPlayers = Players:GetPlayers()
for i = 1, #GetPlayers do
	coroutine.resume(coroutine.create(function()
		-- Runs this function in parallel for each player.
		PlayerAdded(GetPlayers[i])
	end))
end
Players.PlayerAdded:Connect(PlayerAdded) -- Listen for new players.
1 Like