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

How do I search all of the players on a team?

Asked by 10 years ago

I need to be able to send a GUI to all of the Players on a team. This is what I have so far.

players = game.Players:GetChildren()
for i=#players,1 do
    if game.Players[i].TeamColor == game.Teams["My Team"].TeamColor then
        gui = script.Parent.alarm_gui:clone()
        gui.Parent = game.Players[i].PlayerGui
    end
end

However it errors out here:

if game.Players[i].TeamColor == game.Teams["My Team"].TeamColor then

The Output says "1 is not a Valid member of Players"

1 answer

Log in to vote
1
Answered by 10 years ago

Looks fine as far as I can tell, except line 2. For loops require that the lesser number goes last, so it should be:

for i = 1, #players do

Another thing is that you're trying to refer to a table that doesn't exist when you say game.Players[i]. Since the loop is going through the players table you have already defined, it should be players[i].TeamColor, for instance.

Also, it's :Clone(), not clone(). That was just bugging me, it's really just proper syntax :P

0
Oh. I see what you mean. Thank you! duckhunter392 25 — 10y
Ad

Answer this question