Hello, I have a game where a player is put inside a "playersAlive" table. The only problem is that when they leave the game, the game itself doesn't recognize that they have left, and the round will not reset even when everyone else has died.
I was wondering how I could remove a player from the "playersAlive" table when they leave the game. Thanks in advance!
Create an event listener to detect when a player leaves the game.
game.Players.PlayerRemoving:Connect(function(player) local index = table.find(playersAlive, player) if (index) then table.remove(playersAlive, index) end end)
Make sure you define your playersAlive variable at the highest scope possible; it should look something like this:
local playersAlive = {} while (true) do wait(1) -- do round stuff end game.Players.PlayerRemoving:Connect(function(player) local index = table.find(playersAlive, player) if (index) then table.remove(playersAlive, index) end end)
If you defined the variable inside of the while loop, the event listener at the bottom of the script wouldn't recognize the variable.