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 11 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.

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

However it errors out here:

1if 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 11 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:

1for 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 — 11y
Ad

Answer this question