How to Use Or Correctly?

So im trying to check IntroTag and AFK.
Heres what im trying to achieve.

IntroTag | AFK
false | false = Insert Player in Table.
false | true = Remove Player from Table on Behalf of AFK.
True | false = Remove Player from Table on Behalf of IntroTag.
True | True = Remove the Player from Table on Behalf of Both the, IntroTag and AFK.

    local plrs = {}
        	
        	for i, player in pairs (game.Players:GetPlayers()) do
			  	if (player.IntroTag.Value or player.AFK.Value) == false then 
        			table.insert(plrs,player)--Add each players into plrs table
        			print(player)
				else 
					warn(player, 'has Been Removed From Table - Intro Or AFK.')
					for i = 1, #plrs do
					if plrs[1] == Player then
					table.remove(plrs,i) --Remove Player from table if they are in the intro or AFK.
1 Like

You need to compare twice when comparing multiple values. Unlike most other languages, the or (as well as and) operator compares directly at the location of the call - independent of any parenthesis or order.

To properly achieve what you’re trying with that snippet, you need to do this:

if player.IntroTag.Value == false or player.AFK.Value == false then
    -- 1 of the values are false.
elseif player.IntroTag.Value == true and player.AFK.Value == false then
    -- IntroTag is true, but AFK is false
--etc
end
2 Likes

For Some reason this does not work :confused:

You just want

if (player.IntroTag.Value or player.AFK.Value) then
    --remove
else
    --insert
end

You don’t need to use == or ~= to compare BoolValue.Value to true or false, the property is already a boolean. I edited my shorthand pseudocode to put in your fully-qualified value object references so that it’s perfectly clear what I meant.

3 Likes
if (not player.IntroTag.Value) and (not player.AFK.Value) then 
  -- both values are false
  print(player, "add to table")
elseif player.IntroTag.Value == true and player.AFK.Value == false then
  -- IntroTag is true, but AFK is false
elseif player.IntroTag.Value == false and player.AFK.Value == true then
  -- IntroTag is false, but AFK is true
else 
  -- both are true
  print(player, "del from table")
end
1 Like

Your Solution Did not Work. Hmm :confused:

Yours did not work either… :confused: Whats Going on!

for i = 1, #plrs do
	if plrs[1] == Player then
	table.remove(plrs,i)

If I’m not mistaken, this will always remove the first player in the table, since it’s plrs[1].

1 Like

This code is being overcomplicated. You do not need to use table.remove, just don’t insert the player! Is there a reason you need to know why the player was not added to the match?

local Player = game.Players.LocalPlayer
local plrs = {}
        	
for i, player in pairs (game.Players:GetPlayers()) do 
      if not player.IntroTag.Value and not player.AFK.Value then 
          table.insert(plrs,player)--Add each players into plrs table
          print(player)			
       end
end

Sorry for the formatting, I am currently on mobile

3 Likes

Also, what’s the use case for this script?

Yes. But If One is false and other is true would it still remove them? Just Like if both are false. Will it insert them?

Can’t do much with Your solution did not work; what are errors are you getting?

The Game Gets no errors. Just It does not remove the player from the table.

The code I provided will only insert them if they are not AFK and they are not in the intro. (IntroTag is false and AFK is false)

There is NO reason to remove players from the table. Just do not add them in the first place!

1 Like

The not operator is used in both checks for the values, so as long as both nots return correct (that is, that neither of the values are true), the player will be added.

I understand why ImageLabel’s wouldn’t work, where he has:
if not (player.IntroTag.Value and player.AFK.Value) then
the correct parentheses placement would be:
if (not player.IntroTag.Value) and (not player.AFK.Value) then

These are not logically equivalent. not (A or B) is equivalent to (not A) and (not B)
and not (A and B) is equivalent to (not A) or (not B)

But mine matches your truth table, so it would only not work if there are some bad assumptions about what those value objects are, i.e. if they are not BoolValues.

1 Like

The point is; Your problem has been solved. Unless there is something you want that you did not mention, please refer to the solution that seems the easiest and most satisfactory to you.

@ImageLabel This Does not work. Im Doing everything right.

 local plrs = {}
	        	
	        	for i, player in pairs (game.Players:GetPlayers()) do
			  	if not (player.IntroTag.Value) and (player.AFK.Value) then 
        			table.insert(plrs,player)--Add each players into plrs table
        			print(player)
				elseif player.IntroTag.Value == true and player.AFK.Value == false then
					warn(player, 'has Been Removed From Table - Intro Or AFK.')
					for i = 1, #plrs do
					if plrs[1] == Player then
					table.remove(plrs,i) --Remove Player from table if they are in the intro or AFK.
				elseif player.IntroTag.Value == false and player.AFK.Value == true then
					warn(player, 'has Been Removed From Table - Intro Or AFK.')
					for i = 1, #plrs do
					if plrs[1] == Player then
					table.remove(plrs,i) --Remove Player from table if they are in the intro or AFK.
				else
						print("ok")

cc @ImageLabel

This will not work because the item has to be added to be removed; You never insert the player if either of the elseifs is run. Is there a reason you have been ignoring my completely working code? Why do you need to remove items in the first place if you never add them?


local Player = game.Players.LocalPlayer
local plrs = {}
        	
for i, player in pairs (game.Players:GetPlayers()) do 
      if not player.IntroTag.Value and not player.AFK.Value then 
          table.insert(plrs,player)--Add each players into plrs table
          print(player)			
       end
end
1 Like

@REALTimothy0812 Ok But this does not work. At First It does. but when the intro is false but AFK is true it still inserts me into the table