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)
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.
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.
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.