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

Get the rest of the players

Asked by 10 years ago
local rp = gt[math.random(1,#gt)]

So now i have the random player, but how do i get the rest of them? I want everyone else than the random player

2 answers

Log in to vote
2
Answered by
modFrost 130
10 years ago

If you want everyone other then 1 player it would be somewhat like this,

for _,Player in pairs(gt) do -- For all the players
    if not Player == rp then -- If player is not the randomly selected player
        --Etc.
    end
end

or if you wanted them to be in a table,

local OtherPlayers = {}
for _,Player in pairs(gt) do
    if not Player == rp then
        table.insert(OtherPlayers, Player)
    end
end

'OtherPlayers' now has every player but your random one.

0
But @Frostftw could you make that if everyone else than that random player have their health to 0 then it would disable a script? could you make that markus6 5 — 10y
Ad
Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago
for i, v in pairs(gt) do
    if v == rp then
        gt:remove(i)
        break
    end
end

Now, gt only contains unselected players.

Answer this question