I have two scripts that are supposed to work together to determine the frozen player. (They communicate by changing their names)
script 1:
_G.scriptperson2 = script.Parent.gamelogic function display(text) local text2 = game.ServerStorage.text.Value text2 = text wait(3) text2 = "" end while true do repeat wait() until _G.scriptperson.Name == "ready" repeat wait() until _G.Team2Player.Character.ingame.WalkSpeed == 0 wait(3) if _G.scriptperson2.Name ~= "checkdone" then script.Name = "checkdone" _G.scriptperson2.Disabled = true for i,v in pairs(game.Players:GetChildren()) do if v.TeamColor == "Bright blue" then v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1 end end display("Red captain has been frozen! Blue team wins!") script.Name = "gamedone" wait(1) script.Name = "gamelogic2" _G.scriptperson2.Disabled = false elseif _G.scriptperson2.Name == "checkdone" then return end end
script 2:
_G.scriptperson3 = script.Parent.gamelogic2 function display(text) local text2 = game.ServerStorage.text.Value text2 = text wait(3) text2 = "" end while true do repeat wait() until _G.scriptperson.Name == "ready" repeat wait() until _G.Team1Player.Character.ingame.WalkSpeed == 0 if _G.scriptperson3.Name ~= "checkdone" then _G.scriptperson3.Disabled = true script.Name = "checkdone" for i,v in pairs(game.Players:GetChildren()) do if v.TeamColor == "Bright red" then v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1 end end display("Blue captain has been frozen! Red team wins!") script.Name = "gamedone" wait(1) script.Name = "gamelogic" _G.scriptperson3.Disabled = false elseif _G.scriptperson3.Name == "checkdone" then return end end
For the most part, they work perfectly, the check for the names of the other scripts and change their own names accordingly, but one thing is wrong! It skips the entire block of each code that goes:
for i,v in pairs(game.Players:GetChildren()) do if v.TeamColor == "Bright red" then v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1 end end display("Blue captain has been frozen! Red team wins!")
Why does it do this? Neither of the scripts break. They keep looping the way they are supposed to, it just skips the block above in each of them.
The expression
playerInstance.TeamColor == "Bright red"
will always be false. This is because TeamColor is a BrickColor value, and "Bright red" is a string.
a == b
is always false when a
and b
are different types. In this case, a
is a BrickColor and b
is a string, so we know without having to actually check that playerInstance.TeamColor == "Bright red"
is false.
This section in the BrickColor article tells us that we can compare BrickColor values using equals, or their names (which are strings).
We can change this to one of the following (or one of several others):
playerInstance.TeamColor == BrickColor.new("Bright red") playerInstance.TeamColor.Name == "Bright red"