How do I change and check the player's team based ONLY on BrickColor?

I have a script that I want to change the player’s team when they die. This would normally be easy, but another script in the game changes the team’s name based on the amount of players inside of it.

I’ve tried many different approaches (searching through teams by if their name contains something, etc.) but none of these work. I decided to check and change the brickcolor of the player’s team instead, as that was the only alternative that I could think of.

The issue is that the condition in the code is never met. I’ve even disabled the script that changes the names and the code doesn’t work, and the only solution I can find is use team names instead (and, as I’ve stated before, I can’t.) Is there any way to solve this or am I going to have to disable the other script?

Also, I’ve checked multiple times and the brickcolors are correct.

local teams = game:GetService("Teams")

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char.Humanoid.Died:Connect(function()
			print("player died")
			if plr.Team.TeamColor == BrickColor.new("Baby blue") then
				plr.TeamColor = BrickColor.new("Bright blue")
			end
		end)
	end)
end)
2 Likes

Does player died print? Also where is this script located

You’ll have to disable the other script, or change around how it works. The code you provided works just fine if there are two teams with those colors. It’s definitely something to do with how you set up the teams, or the other script conflicting with the one you posted here.

Yes it does, and it’s in Workspace.

The strange thing is I’ve seen other people do this (change and check teams using brickcolors) and that doesn’t seem to work. There are definitely two teams with this color, so I don’t think it’s an issue with that.

You could use variables to define the teams when the server starts and change the player’s team to one of those variables

I tried that and it also doesn’t seem to work…

Do not user .new() for checking brickcolor, use BrickColor.Name

Example:

local teams = game:GetService("Teams")

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char.Humanoid.Died:Connect(function()
			print("player died")
			if plr.Team.TeamColor.Name == "Baby blue" then -- changed line of code
				plr.TeamColor = BrickColor.new("Bright blue")
			end
		end)
	end)
end)

BrickColor has a name property, you use this for conditional statements.