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

Selecting players on a team?

Asked by 8 years ago

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

0
All these views, but no answers WowYouUgly 0 — 8y
0
What does "select" mean? 1waffle1 2908 — 8y
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. WowYouUgly 0 — 8y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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

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? WowYouUgly 0 — 8y
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. 1waffle1 2908 — 8y
0
Note: The actual name of the team does not matter, only the color. 1waffle1 2908 — 8y
Ad

Answer this question