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.
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
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.
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
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
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.
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")
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