You can use table.remove
when choosing alien
so that it returns the removed value, while at the same time nullifying it from the table players
.
Therefore, whenever you iterate through players
later on in your code, it will returned everyone but the removed value, alien.
01 | local playerstorage = game:GetService( "Players" ) |
02 | local storage = game:GetService( "ServerStorage" ) |
03 | local guifolder = storage.Guis |
07 | for _, player in pairs (game.Players:GetPlayers()) do |
08 | if player and player.Character then |
09 | local humanoid = player.Character:WaitForChild( "Humanoid" ) |
10 | if humanoid and humanoid.Health > 0 then |
11 | table.insert(players, player) |
18 | local alien = table.remove(players, math.random(#players) |
19 | local alieng = guifolder.Alien |
20 | local alieng 2 = alieng:Clone() |
21 | alieng 2. Parent = alien.PlayerGui |
23 | for _, player in pairs (players) do |
31 | print '2 players needed!' |
Also, in your first generic for loop, you are iterating through the table returned by players:GetPlayers
, which only returns player objects.. therefore, you do not need to check if they have a character, because that's a given.
1 | for _, player in pairs (game.Players:GetPlayers()) do |
2 | local humanoid = player.Character:WaitForChild( "Humanoid" ) |
3 | if humanoid and humanoid.Health > 0 then |
4 | table.insert(players, player) |