Okay so I have a table in a script that contains the players. And when they leave, if they are part of the table then remove. Is this possible? I attempted with....
gamePlayers = {}
playersInGame = 0
function addPlayers()
gamePlayers = {}
playersInGame = 0
for _, player in pairs(game.Players:GetChildren()) do
if player:FindFirstChild("PlayerValues").ReadyToPlay.Value == true then
table.insert(gamePlayers, player)
playersInGame = playersInGame + 1
end
end
end
function search(tab, val)
for i, v in pairs(tab) do
if val == v then
return i
end
end
end
game.Players.PlayerRemoving:connect(function(leavingPlayer)
local i = search(gamePlayers, leavingPlayer)
if i then
table.remove(gamePlayers, i)
print(leavingPlayer.Name.." Has Left")
playersInGame = playersInGame - 1
end
end)
repeat wait(1)
addPlayers()
until playersInGame > 1
error :"bad argument #2 to 'find' (string expected, got no value)"

3 comments
So you want the script to run when a Player leaves? Does the table keep track if people are alive or anything, or are you just using it to know what people are in the game?
know what people are in the game
Like, I have a table of the players that are in the game, and when they leave, it removes their name from the table, and checks to see if their name is even in the table first