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

How to fix this "If" statement by using TeamColor property?

Basically, after a player clicks a button, it checks the player's *TeamColor *property and if it the player's TeamColor were to be "Bright blue" then they'd get teleported to their base. To be more specific, a Part's Position.

I know how to get the Player's Character and as well to move it to the Part's Position using MoveTo. I can explain the problem better with comments in my code:

if plr.TeamColor == "Bright blue" then

	plr.Character:MoveTo(workspace.GLOBAL_SPAWNS.BlueS.Position) --if I were to really be in Blue's team, this part is skipped.

else

	plr.Character:MoveTo(workspace.GLOBAL_SPAWNS.RedS.Position) --this part is ran only, and obviously a Blue Teammate does not belong in the Red base.			
				
end

I have a feeling that I'm getting the correct property of TeamColor. plz help c:

**NOTE: I have every variable, like 'plr', defined else where in the complete script.

1 answer

✓ Accepted answer

The reason your code does not work as expected is because you are comparing two different types of variables with each other in your conditional statement.

In other words, if plr.TeamColor == "Bright blue" then is wrong because the TeamColor property does not take a String, it takes a BrickColor!

You can verify this by checking the wiki, which says that the Value Type is BrickColor. not String. Naturally, if you don't compare the property with a BrickColor, your statement will never be true.

Fix this by changing your line to this... if plr.TeamColor == BrickColor.new("Bright blue") then.

1 comment

0

Thank you, it works! Before posting the question, I thought I had to do this but didn't. I thought that 'BrickColor.new' was for setting properties than by checking them.

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