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

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

Asked by
xPolarium 1388 Moderation Voter
9 years ago

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

Log in to vote
5
Answered by
Unclear 1776 Moderation Voter
9 years ago

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.

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. xPolarium 1388 — 9y
Ad

Answer this question