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

Basically, how do I make an if not statement out of this line of code?

The forementioned excerpt line of code says..

'if players' teamcolor is the same as the soldier teamcolor, then return end.

For that purpose, it is fine. However, what is the easy fix to make it say

'if players' teamcolor is NOT the same as the soldier teamcolor, then return end.'

??

Respectfully, M

--

if (p.TeamColor == game.Teams["soldier"].TeamColor) then return end

1 comment

3 answers

Relational operators

A relational operator is something that returns a boolean value based on the relationship between both it's operands. You can read about all the relational operators on the wiki here. What you're looking for, is the not-equal-to operator, which looks like this: ~= (in Lua).

Not-equal-to

The not-equal-to operator is pretty self-explanatory. It will return true only if both it's operands are not equal to one another. For example, print(1 ~= 2) would yield true, since 1 does not equal 2. The solution to your problem would be identical:

if p.Team ~= game.Teams.soldier then
	return
end

There's also the not operator, which is similar in terms of returning the opposite of it's inequality. It's not what you'd need for this situation, but if you'd like to know more about it you can check out my old answer on it here.

Edit

As Goulstem mentioned, Team is now a member of each player which represents their team directly. The need to compare team colors to find out which team the player is on is now obsolete.

You can use the ~= comparative operator to resemble if something isn't equivalent.

  • Note: 'Team' is now a Property of Players.

Ex;

if p.Team ~= game.Teams["soldier"] then return end

The comparative symbol ~= is the opposite of == in a way that it means "Not" Also roblox has now implemented "Team" As a player property so your code could look something like this

if p.Team ~= game.Teams["soldier]" then return end

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