Team changeing commands

Hello Dev Forum! I am trying to make a command like /e cc and that command well change that player to the Chris’s Cafe team!

Now some of you maybe thinking well chcek the toolbox there are a lot of them but not like the way I need it. I need it to be rank locked.

I have looked it up and checked the toolbox and I have found nothing that fits my needs.

Got any tips?

1 Like

This article has code that allows a player to change teams by doing “/jointeam TeamName”, you could always tweak the code to change the command.

I don’t quite understand what you mean by this:

I will have a look into the article and I fixed what you said you did not understand. Do you understand it better now?

I’m not quite sure what you mean by rank locked.

So the player has to be in the group but there rank id has to be above 3 and anyone who is blow 3 cant join the team.

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.