I'm trying to use this part of code for a training center, the values and everything work, but if the player is on any team it team's them to white. I only want the people on team Really red and Really blue to be teamed white, any one know why this won't work?
function EventEnd() game.ServerStorage.Mode.Value = "None" game.Workspace.MapHolder:ClearAllChildren() Get = game.Players:GetChildren() for i = 1,#Get do Get[i].leaderstats.Kills.Value = 0 Get[i].leaderstats.Deaths.Value = 0 if Get[i].TeamColor == BrickColor.new('Really red') or BrickColor.new('Really blue') then Get[i].TeamColor = BrickColor.new('White') wait(0.1) Get[i]:LoadCharacter() TeamOne = 0 TeamTwo = 0 end end end
First, two important issues: 1: tab your code correctly; 2: use meaningful variable names:
function EventEnd() game.ServerStorage.Mode.Value = "None" game.Workspace.MapHolder:ClearAllChildren() local players = game.Players:GetPlayers() -- Use GetPlayers, not GetChildren for i = 1, #players do local player = players[i] player.leaderstats.Kills.Value = 0 player.leaderstats.Deaths.Value = 0 if player.TeamColor == BrickColor.new('Really red') or BrickColor.new('Really blue') then player.TeamColor = BrickColor.new('White') wait(0.1) player:LoadCharacter() TeamOne = 0 TeamTwo = 0 end end end
Now, let's look at the condition.
It turns out that or
is lower precedence than *==
. That means how this evaluates:
if (team == red) or blue then
that will always be "true" since if team == red
is false
, blue
is "true enough" and the condition will pass (or
takes the "truer" of the two)
If we put parenthesis:
if team == (red or blue) then
This wouldn't work either. (red or blue)
is just red
-- you can't have one expression have two values.
You have to be explicit:
if team == red or team == blue then
(I am using some "pseudo code" here, e.g.
red
,team
andblue
to keep things a little shorter and clearer -- this isn't the actual code you would type)