for _, v in pairs(Players:GetPlayers()) do
table.insert(Settings.ALL_PLAYERS, v)
end
print(#Settings.ALL_PLAYERS) -- prints 2
Settings.ACTIVE_PLAYERS = Settings.ALL_PLAYERS
-- When a player dies, remove them from the ACTIVE_PLAYERS table, but they STAY in the ACTIVE_PLAYERS TABLE
character.Humanoid.Died:Connect(function()
for i, v in pairs(Settings.ACTIVE_PLAYERS) do
if v == player then
table.remove(Settings.ACTIVE_PLAYERS, i)
end
end
end)
-- At end of round check for all players who played that round
print(#Settings.ALL_PLAYERS) -- only prints 1
for _, player in pairs(Settings.ALL_PLAYERS) do
print(player) -- only prints 1, prints the active player
end
So what I am doing is starting a round and killing one player, so that 1 player gets removed from the ACTIVE_PLAYERS table, however when I do a loop at the end of ALL_PLAYERS it only shows the active player. The only other time I set data inside the ALL_PLAYERS table is at the very end with
ALL_PLAYERS = {}
which runs a couple seconds after this loop (so the loop for all players runs before the all players table is reset to empty)
So my question is, because I’m setting ACTIVE_PLAYERS to == ALL_PLAYERS does that overide ALL_PLAYERS??
Basically, ACTIVE_PLAYERS should equal ALL_PLAYERS at the start. ALL_PLAYERS should remain constant throughout the game. ACTIVE_PLAYERS is the one that gets values removed, as it only contians the active players in game
local Array1 = {"John","Sarah","Ann"}
local Array2 = {"Nick","Carl","Dre"}
Array2 = Array1
table.remove(Array2, 2) -- shoould remove "sarah"
for k,v in pairs(Array1) do
print(k,v)
end
for k,v in pairs(Array2) do
print(k,v)
end
Yes i believe it does override the ALL_PLAYERS tables, (as mentioned above) in fact i believe it just sets the tables to the same table so when you were to remove a value from All_Players, ACTIVE_PLAYERSthe value will also get removed from that tables aswell
i use this sometimes for cloning tables
function NewTable(...)
local NewTable = {}
local Args = ...
if typeof(Args) ~= "table" then
Args = {...}
end
for _, val in pairs(Args) do
table.insert(NewTable, val)
end
return NewTable
end
local Table = {5,3}
local Table2 = {2,1}
Table = NewTable(Table2)
table.insert(Table,9)
for i,v in pairs(Table2) do
print(v) --- would print 2 and 1
end
Here’s my theory, you joined at different times, and unless you added a characteradded/playeradded event, there will theoretically only be 1 player in it at all times
for _, v in pairs(Players:GetPlayers()) do
table.insert(Settings.ALL_PLAYERS, v)
end
print(#Settings.ALL_PLAYERS) -- prints 2
Settings.ACTIVE_PLAYERS = Settings.ALL_PLAYERS
-- When a player dies, remove them from the ACTIVE_PLAYERS table, but they STAY in the ACTIVE_PLAYERS TABLE
character.Humanoid.Died:Connect(function()
for i, v in pairs(Settings.ACTIVE_PLAYERS) do
if v == player then
table.remove(Settings.ACTIVE_PLAYERS, i)
end
end
end)
-- At end of round check for all players who played that round
print(#Settings.ALL_PLAYERS) -- only prints 1
for _, player in pairs(Settings.ALL_PLAYERS) do
print(player) -- only prints 1, prints the active player
end
As mentioned, the ALL_PLAYERS print 2, so there are 2 players in it