print(script.Name..' loaded') local players= game.Players local surviving= { } roundActive= false intermission= true game.Players.PlayerAdded:connect(function(player) table.insert(surviving, player.Name) print(player.Name..' has joined the game') print(table.concat(surviving, ', ')) player.CharacterAdded:connect(function(character) character.Humanoid.Died:connect(function() table.remove(surviving, player.Name) print(player.Name..' has died') end) end) end) game.Players.PlayerRemoving:connect(function(player) if surviving:findFirstChild(player.Name) then table.remove(surviving, player.Name) else end print(player.Name..' has left') end) function getNewList() local plr= players:GetChildren() for i= 1,#plr do if surviving:findFirstChild(plr[i].Name) then print(plr[i].Name..' is already in the roster') else table.insert(surviving, plr[i].Name) print(plr[i].Name..' added to the roster') end end end function announceSurvivors() print(table.concat(surviving, ', ')) end
The FindFirstChild
method does not work with arrays
(tables
).
for key,value in pairs(surviving) do -- the pairs function is not necessary. if player.Name==value then -- code end end
The table.remove
function removes the value at the index given. To remove a specific value you can loop through the table.
function removeValue(tab, val) for o, n in pairs(tab) do if val == n then table.remove(tab, o) end end end
removeValue(surviving, player.Name)