Team game pass checker

This is the team changer script I have for the GUI :
local Opened = false
local Teams = game:GetService(“Teams”)

script.Parent.Team.MouseButton1Click:Connect(function()
if Opened == false then
script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,0.266, 0))
Opened = true
else
script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,-0.9, 0))
Opened = false
end
end)

script.Parent.Frame.Imam.MouseButton1Click:Connect(function()
script.Parent.Parent.Parent.Team = Teams.Imam
script.Parent.Parent.Parent.Team.TeamColor = Teams.Imam.TeamColor
wait()
script.Parent.Parent.Parent:LoadCharacter()
end)

script.Parent.Frame.Normal.MouseButton1Click:Connect(function()
script.Parent.Parent.Parent.Team = Teams.Normal
script.Parent.Parent.Parent.Team.TeamColor = Teams.Normal.TeamColor
wait()
script.Parent.Parent.Parent:LoadCharacter()
end) but i have this script in the work place
local player = game.Players.LocalPlayer
local gamepassId = 162872866
local hasGamepass = player:PlayerHasPass(gamepassId)

if hasGamepass then
player.Team = game.Teams.Imam
end
and it doesn’t wor. How do I make it so it checks if the player owns it?

This may help, try using this instead of :PlayerHasPass()

UserOwnsGamepassAsync(player.UserId, gamepassId)
1 Like

i don’t know how to apply it. im new to scripting

im confused on how to apply this in my game.

like this? local Opened = false
local Teams = game:GetService(“Teams”)
local MarketplaceService = game:GetService(“MarketplaceService”)
local GamePassId = 162872866 – replace with your game pass ID

script.Parent.Team.MouseButton1Click:Connect(function()
if Opened == false then
script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,0.266, 0))
Opened = true
else
script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,-0.9, 0))
Opened = false
end
end)

script.Parent.Frame.Imam.MouseButton1Click:Connect(function()
if MarketplaceService:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, GamePassId) then
script.Parent.Parent.Parent.Team = Teams.Imam
script.Parent.Parent.Parent.Team.TeamColor = Teams.Imam.TeamColor
wait()
script.Parent.Parent.Parent:LoadCharacter()
else
game:GetService(“MarketplaceService”):PromptGamePassPurchase(game.Players.LocalPlayer, GamePassId)
end
end)

script.Parent.Frame.Normal.MouseButton1Click:Connect(function()
if MarketplaceService:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, GamePassId) then
script.Parent.Parent.Parent.Team = Teams.Normal
script.Parent.Parent.Parent.Team.TeamColor = Teams.Normal.TeamColor
wait()
script.Parent.Parent.Parent:LoadCharacter()
else
game:GetService(“MarketplaceService”):PromptGamePassPurchase(game.Players.LocalPlayer, GamePassId)
end
end)

Alright. Let me help. Let’s start with this snippet from the end of your code.

local MS = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local gamepassId = 162872866
local hasGamepass = MS:UserOwnsGamepassAsync(player.UserId, gamepassId)

if hasGamepass then
    player.Team = game.Teams.Imam
end
1 Like

okay, thank you. I will follow your instructions. Wait why do I put that in the bottom and not the top?

If it still doesn’t work, there may be another issue. How did you get your gamepassId? That may be another reason why it doesn’t work.

(Quick tip, add three ``` in front and then behind your code to format it in Lua, makes it easier to read)

Okay, ```local MS = game:GetService(“MarketplaceService”)
local player = game.Players.LocalPlayer
local gamepassId = 162872866
local hasGamepass = MS:UserOwnsGamepassAsync(player.UserId, gamepassId)

if hasGamepass then
player.Team = game.Teams.Imam
endThe game pass id is correct. But do I puit the code you gave at the bottom bellow:script.Parent.Frame.Normal.MouseButton1Click:Connect(function()
script.Parent.Parent.Parent.Team = Teams.Normal
script.Parent.Parent.Parent.Team.TeamColor = Teams.Normal.TeamColor
wait()
script.Parent.Parent.Parent:LoadCharacter()
end)```

Yeah, just replace the end of your code that you posted earlier. I just took it out and modified it to where it should work in your case.

Should it look like this?

local Teams = game:GetService("Teams")

script.Parent.Team.MouseButton1Click:Connect(function()
	if Opened == false then
		script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,0.266, 0))
		Opened = true
	else
		script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,-0.9, 0))
		Opened = false
	end
end)

script.Parent.Frame.Imam.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Team = Teams.Imam
	script.Parent.Parent.Parent.Team.TeamColor = Teams.Imam.TeamColor
	wait()
	script.Parent.Parent.Parent:LoadCharacter()
end)

script.Parent.Frame.Normal.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Team = Teams.Normal
	script.Parent.Parent.Parent.Team.TeamColor = Teams.Normal.TeamColor
	wait()
	script.Parent.Parent.Parent:LoadCharacter()
end)
local MS = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local gamepassId = 162872866
local hasGamepass = MS:UserOwnsGamepassAsync(player.UserId, gamepassId)

if hasGamepass then
	player.Team = game.Teams.Imam
end'
local Opened = false
local Teams = game:GetService("Teams")

script.Parent.Team.MouseButton1Click:Connect(function()
	if Opened == false then
		script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,0.266, 0))
		Opened = true
	else
		script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,-0.9, 0))
		Opened = false
	end
end)

script.Parent.Frame.Imam.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Team = Teams.Imam
	script.Parent.Parent.Parent.Team.TeamColor = Teams.Imam.TeamColor
	wait()
	script.Parent.Parent.Parent:LoadCharacter()
end)

script.Parent.Frame.Normal.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Team = Teams.Normal
	script.Parent.Parent.Parent.Team.TeamColor = Teams.Normal.TeamColor
	wait()
	script.Parent.Parent.Parent:LoadCharacter()
end)
local MS = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local gamepassId = 162872866
local hasGamepass = MS:UserOwnsGamepassAsync(player.UserId, gamepassId)

if hasGamepass then
	player.Team = game.Teams.Imam
end
local Opened = false
local Teams = game:GetService("Teams")

script.Parent.Team.MouseButton1Click:Connect(function()
	if Opened == false then
		script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,0.266, 0))
		Opened = true
	else
		script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,-0.9, 0))
		Opened = false
	end
end)

script.Parent.Frame.Imam.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Team = Teams.Imam
	script.Parent.Parent.Parent.Team.TeamColor = Teams.Imam.TeamColor
	wait()
	script.Parent.Parent.Parent:LoadCharacter()
end)

script.Parent.Frame.Normal.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Team = Teams.Normal
	script.Parent.Parent.Parent.Team.TeamColor = Teams.Normal.TeamColor
	wait()
	script.Parent.Parent.Parent:LoadCharacter()
end)
local MS = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local gamepassId = 162872866
local hasGamepass = MS:UserOwnsGamepassAsync(player.UserId, gamepassId)

if hasGamepass then
	player.Team = game.Teams.Imam
end```

Yeah, that looks right! If you get any error please send it.

Your error is that you haven’t used pcall here and it will only be in client here is fixed one and use basic script:

local MarketplaceService = game:GetService("MarketplaceService")


local GamePassId = 162872866

game.Players.PlayerAdded:Connect(function(Player)
	local HasPass = false
	local success, message = pcall(function()
		HasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassId)
		print(HasPass)
	end)
	if HasPass == true then
        Player.Team = game.Teams.Imam
	end
end)

1 Like

Okay, thank you. I will test it out.

Thanks! I’m a bit new as well :smile:

1 Like

play from the last third line is underlined yellow

Oh sorry small error i will change it now

I changed it try now

It didn’t work. I do not why. It changed the player to Imam team.

It doesn’t work. Here: (6) [Eid Mubarak] MASQUE​:tada: :confetti_ball: - Roblox you can see. It just changed the player team and that’s it.