Answered by
6 years ago Edited 6 years ago
There are multiple ways to find a player's team.
For checking for the team's name, you can either:
- Compare the player's
Team
to the corresponding Team
in the Teams
service:
1 | script.Parent.Touched:Connect( function (hit) |
2 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
4 | if player.Team = = game:GetService( "Teams" ):FindFirstChild( "Team name" ) then |
- Compare the player's Team's
Name
to a string (because the Name
property itself is a string). This works because Team
is a reference property that refers to the player's Team:
1 | script.Parent.Touched:Connect( function (hit) |
2 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
4 | if player.Team.Name = = "Team name" then |
If you instead want to find the team's color, then you would compare it to a BrickColor
:
1 | script.Parent.Touched:Connect( function (hit) |
2 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
4 | if player.TeamColor = = BrickColor.new( "Color name" ) then |
Variant 2 of the above code:
1 | script.Parent.Touched:Connect( function (hit) |
2 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
4 | if player.Team.TeamColor = = BrickColor.new( "Color name" ) then |