Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to compare color value in for loops?

Asked by 10 years ago

How do I compare team to Bright red?

function tele()
wait()
    c=game.Players:GetChildren()
    for i=1, #c do
        team = c[i].TeamColor

            if team == "Bright red" then <-----Problem here
                   print("RED")
            end
    end
end

while true do
wait(5)
tele()
end
0
BrickColor.new("Bright red") M39a9am3R 3210 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

To expound on what M39 said, TeamColor is a type of value called a BrickColor value. What that line of script is doing therefore is comparing some letters ("Bright Red") to a Color value, which clearly colors and letters aren't the same thing so it spits out an error. That's why you have to say:

if team == BrickColor.new("Bright Red") then
    --in this case you're asking it to make sure that the colors are the same
end
0
Thanks! +1ed Orlando777 315 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

I ran into this problem and fixed it like so:

function tele()
wait()
    c=game.Players:GetChildren()
    for i=1, #c do
        team = c[i].TeamColor

            if team.Name == "Bright red" then --.Name adds the string value tag so it will match string "Bright red"
                   print("RED")
            end
    end
end

while true do
wait(5)
tele()
end

Answer this question