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

Is it possible to get a Player's team?

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

✓ Accepted answer
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.

1 comment

0

Thanks!

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

2 comments

0

If multiple teams have the same color then this would return the first found.

0

If multiple teams had the same color then you would only be able to be on the first team.

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