local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message, Recipient)
if Recipient then
return
end
local SplitMessage = Message:split(" ")
if #SplitMessage >= 2 then
if SplitMessage[1]:lower():match("^:team") then
local TeamsFound = {}
for _, Team in ipairs(Teams:GetTeams()) do
if Team.Name:lower():match("^"..SplitMessage[2]) then
table.insert(TeamsFound, Team)
end
end
if #TeamsFound == 1 then
print("One team was found.")
local Team = TeamsFound[1]
Player.Team = Team
elseif #TeamsFound == 0 then
warn("No teams were found.")
else
warn("Too many teams were found.")
end
end
end
end)
end)
Here’s the same script but with the group member/group rank requirements included.
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local ProtectedCall = pcall
local GroupId = 0
local GroupRank = 0
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message, Recipient)
if Recipient then
return
end
local SplitMessage = Message:split(" ")
if #SplitMessage >= 2 then
if SplitMessage[1]:lower():match("^:team") then
local Success1, Result1 = ProtectedCall(function()
return Player:IsInGroup(GroupId)
end)
if Success1 then
if Result1 then
print("Player in in the group.")
local Success2, Result2 = ProtectedCall(function()
return Player:GetRankInGroup(GroupId)
end)
if Success2 then
if Result2 >= GroupRank then
print("Player's group rank is high enough.")
local TeamsFound = {}
for _, Team in ipairs(Teams:GetTeams()) do
if Team.Name:lower():match("^"..SplitMessage[2]) then
table.insert(TeamsFound, Team)
end
end
if #TeamsFound == 1 then
print("One team was found.")
local Team = TeamsFound[1]
Player.Team = Team
elseif #TeamsFound == 0 then
warn("No teams were found.")
else
warn("Too many teams were found.")
end
else
print("Player's group rank is not high enough.")
end
else
warn(Result2)
end
else
warn("Player is not in the group.")
end
else
warn(Result1)
end
end
end
end)
end)
I have tested this and it works. You can also abbreviate the team’s name providing the abbreviation doesn’t lead to ambiguity, i.e; “:team re” will switch the player’s team to a team named “Red” if it exists. The command’s format is relatively simple being :team [Team Name Here] without the inclusion of the square braces.