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

Selecting players on a team?

I am trying to select the players on a certain team. How would I do this?

3 comments

0

All these views, but no answers

0

What does "select" mean?

0

I'm trying to change the faces of all the players on the black team. To do that I need to "select" all the players on the black team and change their face.

1 answer

If you want to create a list of players with a certain TeamColor, iterate through game.Players:GetPlayers() and check if the player has the specified TeamColor.

If the TeamColor of the team is called "Bright blue" then you can write this:

local blue={}
for _,v in pairs(game.Players:GetPlayers())do
	if v.TeamColor.Name=="Bright blue"then
		blue[#blue+1]=v
	end
end

which will create a table blue of players on the Bright blue team.

edit: the face object is a decal inside the character's head, so to change its Texture for each player on the team, you can index the face and set the texture:

local bluetextureid="rbxassetid://########" -- image id
game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		if player.TeamColor.Name=="Bright blue" then
			local face=character:WaitForChild("Head"):WaitForChild("face")
			face.Texture=bluetextureid
		end
	end
end

edit: changed to run on CharacterAdded rather than one-time

3 comments

0

Thank you so much! I'm confused on the "if character then", "if head then", "if face then" parts. Why would I need them?

0

If there's no character then calling character:FindFirstChild("Head") will error because character is nil and has no properties or methods such as FindFirstChild. Same thing with the head and face.

0

Note: The actual name of the team does not matter, only the color.

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