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
There are multiple ways to find a player's team.
For checking for the team's name, you can either:
Team
to the corresponding Team
in the Teams
service:script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then if player.Team == game:GetService("Teams"):FindFirstChild("Team name") then -- Do stuff here end end end)
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:script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then if player.Team.Name == "Team name" then -- Do stuff here end end end)
If you instead want to find the team's color, then you would compare it to a BrickColor
:
script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then if player.TeamColor == BrickColor.new("Color name") then -- Do stuff here end end end)
Variant 2 of the above code:
script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then if player.Team.TeamColor == BrickColor.new("Color name") then -- Do stuff here end end end)