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

How do I get a players team in a script?

Asked by 6 years ago
Edited 6 years ago

if Player.Team == "Players" then

this doesn't work. How do I get the players team so that I can have certain team members TP somewhere in my game

I'm basically asking how can I make it so the script knows what team a player is on

0
Try finding the Color of the team. So basically if Player.TeamColor == bla bla bla mudathir2007 157 — 6y
0
To find a players team, do one of the following methods: ~~~~~~~~~~~~~~~~~ local team = player.Team local teamColor = player.TeamColor local teamName = player.Team.Name ~~~~~~~~~~~~~~~~~ with further questions/comments/concerns, feel free to reply to my answer. Happy scripting! mc3334 649 — 6y

1 answer

Log in to vote
0
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:
1script.Parent.Touched:Connect(function(hit)
2    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
3    if player then
4        if player.Team == game:GetService("Teams"):FindFirstChild("Team name") then
5            -- Do stuff here
6        end
7    end
8end)
  • 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:
1script.Parent.Touched:Connect(function(hit)
2    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
3    if player then
4        if player.Team.Name == "Team name" then
5            -- Do stuff here
6        end
7    end
8end)

If you instead want to find the team's color, then you would compare it to a BrickColor:

1script.Parent.Touched:Connect(function(hit)
2    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
3    if player then
4        if player.TeamColor == BrickColor.new("Color name") then
5            -- Do stuff here
6        end
7    end
8end)

Variant 2 of the above code:

1script.Parent.Touched:Connect(function(hit)
2    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
3    if player then
4        if player.Team.TeamColor == BrickColor.new("Color name") then
5            -- Do stuff here
6        end
7    end
8end)
Ad

Answer this question