Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

1 comment

0

Oh. I see what you mean. Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.