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

How do I find a player's team?

Asked by 9 years ago

I know to find teams it is

game.Teams:GetChildren

But I want to be able to see if a player is on a certain team and then make the number of players on that team into a variable that gives me a number. I would like to ultimately have something like this:

if playersAlive == 1 then
-- I would want to put what happens next here

If you can help me it would be much appreciated!

0
Your welcome! EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

A player has a property named, "TeamColor". In the Teams Service you can name teams and give them a color.


TeamColor

TeamColor is a BrickColor. This is overwritable. So you can change a player's team through a script.

game:GetService("Players").Player1.TeamColor = BrickColor.new("White") --Changes to white
print(game:GetService("Players").Player1.TeamColor) --Prints "White".

That is really all there is too it. This is how you can see what teams people are on:

--LocalScript
local player = game:GetService("Players").LocalPlayer
local teamname = ""

for _,color in pairs(game:GetService("Teams")) do
    if color == player.TeamColor then
        teamname = color.Name
    end
end

print(player.Name.." is on the "..teamname.." team.")


Hope this helps!

0
Thanks! jimborimbo 94 — 9y
Ad

Answer this question