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

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

Asked by 7 years ago
Edited by OldPalHappy 7 years ago

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

3 answers

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

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.

Ad
Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago

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
Log in to vote
1
Answered by 7 years ago

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

Answer this question