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
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Try finding the Color of the team. So basically if Player.TeamColor == bla bla bla
To find a players team, do one of the following methods:
local team = player.Team local teamColor = player.TeamColor local teamName = player.Team.Namewith further questions/comments/concerns, feel free to reply to my answer. Happy scripting!