Multiple errors when trying to add all players in game to a table

So im trying to make it so all players that are in game and all players that join will appear in a list on my admin panel, and all players that leave will be deleted from it, and im putting them on a table then putting then in the list

But im getting multiple errors like
Invalid argument #2 to 'remove' (number expected, got string)
Attempt to index nil with Name
Invalid argument #1 to 'insert' (number expected, got string)

Heres the code

local PlayList = {}
local target = nil
for i,v in pairs(game:GetService("Players"):GetPlayers()) do 
    if v ~= game.Players.LocalPlayer then 
        table.insert(PlayList,v.Name)
    end
end
game.Players.ChildAdded:Connect(function(newc)
    if newc.Name ~= lplr.Name and not table.find(PlayList,newc.Name) then
        table.insert(PlayList,newc.Name)
    end
end)
game.Players.ChildRemoved:Connect(function(remc)
    if table.find(PlayList,remc.Name) then
    table.remove(PlayList,remc.Name)
    end
end)

table.remove needs the position, you can do this instead:

    table.remove(PlayList, table.find(PlayList,remc.Name))

Which line for the table.insert is give you troubles?

table.remove accepts a numerical index, not the value. You need to do table.remove(PlayList,table.find(remc.Name)). And you should also keep the if statement to check fi the name exists first.

Also, use .PlayerAdded instead of .ChildAdded and .PlayerRemoved instead of .ChildRemoved.

The table.insert isnt giving more errors, i think after i changed it to newc.Name it fixed, thx

Oh ok i did that bc i though there was having something with PlayerAdded and PlayerRemoved

table.find(remc.Name)

Remember you need to pass the table value being queried as the first argument to table.find().

Additionally, as this is a local script the .PlayerAdded event won’t fire. The .PlayerRemoving event on the other hand does fire.

In response to the original post, you may find that a dictionary is more performant than an array.

local players = game:GetService("Players")
local playerList = {}

players.ChildAdded:Connect(function(player)
	if player:IsA("Player") then
		playerList[player] = true
	end
end)

players.PlayerRemoving:Connect(function(player)
	playerList[player] = nil
end)