Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to compare color value in for loops?

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

1 comment

0

BrickColor.new("Bright red")

2 answers

✓ Accepted answer

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

1 comment

0

Thanks! +1ed

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

This discussion is preserved as it was. New answers, comments, and votes are closed.