Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Choosing the rest of the players?

Asked by 9 years ago

I recently asked a question about a bad argument error when choosing a random player. Now, I want a way to implement a gui into the rest of the players.

Go to: to see this previous question.

This is the current code that has to be updated with this feature:

01local playerstorage = game:GetService("Players")
02local storage = game:GetService("ServerStorage")
03local guifolder = storage.Guis
04local players = {}
05 
06wait (40)
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)
12            end
13        end
14    end
15    if #players >= 2 then
View all 26 lines...

2 answers

Log in to vote
1
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

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.

01local playerstorage = game:GetService("Players")
02local storage = game:GetService("ServerStorage")
03local guifolder = storage.Guis
04local players = {}
05 
06wait (40)
07for _, 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)
12    end
13  end
14end
15 
View all 32 lines...

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.

1for _, 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)
5  end
6end
0
Thank you! fight4money -2 — 9y
Ad
Log in to vote
0
Answered by
saenae 318 Moderation Voter
9 years ago

It seems as if all you need is one more loop that just ignores the alien.

for i, v in pairs(game.Players:GetChildren()) do if v.PlayerGui:findFirstChild("Alien") == nil then -- Add Gui end end

Answer this question