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

Is it possible to get a Player's team?

Asked by 9 years ago

I've tried doing this:

player = game.Players.LocalPlayer
if player.Team == "RedTeam" then
    print("worked")
end

It did not print what I asked it to, and showed no errors. And yes RedTeam is in game.Teams. Any help?

2 answers

Log in to vote
3
Answered by 9 years ago
player = game.Players.LocalPlayer
if player.TeamColor == BrickColor.new("Bright red") then
    print("worked")
end

There is no Team property of player. However, there is aTeamColorproperty. So, if we replace player.Team with player.TeamColor, and check for BrickColor.new("Bright red") (Or whichever teamcolor you're using) we can check the player's team.

0
Thanks! PyccknnXakep 1225 — 9y
Ad
Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

Players don't contain a property which tells you their team directly, but they do have the TeamColor property. If you want to get the name of the team from that property, then you need to iterate through Teams until the colors match.

function GetTeamName(player)
    if player.Neutral then return'Neutral'end
    for _,v in pairs(game:GetService("Teams"):GetChildren())do
        if v.TeamColor==player.TeamColor then
            return v.Name
        end
    end
    return'Neutral'
end
0
If multiple teams have the same color then this would return the first found. Goulstem 8144 — 9y
0
If multiple teams had the same color then you would only be able to be on the first team. 1waffle1 2908 — 9y

Answer this question