How would I get the players team?

So I am trying to see if when the player leaves if he is on the Cops or robbers side and it keeps returning “Error”

function Main.PlayerLeave(player)
	local teamFolder = game.Workspace:FindFirstChild("GameInfo")
	if player.Team == BrickColor.Gold then
		teamFolder.Cops.Value -= 1
		print(teamFolder.Cops.Value)
	elseif player.TeamColor == BrickColor.Lapis then
		teamFolder.Robbers.Value -= 1
		print(teamFolder.Robbers.Value)
	else return print("Error")
	end
end

Maybe try?

function Main.PlayerLeave(player)
	local teamFolder = game.Workspace:FindFirstChild("GameInfo")
	if player.TeamColor == BrickColor.new("Gold") then
		teamFolder.Cops.Value -= 1
		print(teamFolder.Cops.Value)
	elseif player.TeamColor == BrickColor.new("Lapis") then
		teamFolder.Robbers.Value -= 1
		print(teamFolder.Robbers.Value)
	else return print("Error")
	end
end

Try using the team Instance instead of the color

function Main.PlayerLeave(player)
	local teamFolder = game:GetService("Teams")
	if player.Team == teamFolder.Cops then
		teamFolder.Cops.Value -= 1
		print(teamFolder.Cops.Value)
	elseif player.Team == teamFolder.Robbers then
		teamFolder.Robbers.Value -= 1
		print(teamFolder.Robbers.Value)
	else return print("Error")
	end
end

Adjust the code as you’d like.

I don’t know why but when I use the service I cannot get the team from the service so I tried this

if player.Team == game.Teams.Cop then```
And that worked!