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 find a player's team?

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!

1 comment

0

Your welcome!

1 answer

✓ Accepted answer

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!

1 comment

0

Thanks!

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