Making a command that teams a specific rank in a group

Hey! I was wondering how I could make it so when a specific rank in a group (for example general manager) chats a command (like !splitteam), it changes the trainees team to randomized trainee teams.


Sorry it was sort of hard to understand.

1 Like
--setting variables for services
local players = game:GetService("Players")
local teams = game:GetService("Teams")

local groupId = -- put your group id here
local rank = -- put the rank thing here, eg 255
local randomTeams = {
    -- put the teams here. examples below
local traineeTeam = -- trainee team

--checking for players joining
    if plr:GetRankInGroup(groupId) == rank then
            if message == "!splitteam" then
                for i,v in pairs(traineeTeam:GetPlayers()) do
                    v.Team = randomTeams[math.Random(1,#randomTeams)]

hopefully this should work

1 Like

Well for chat commands just do


Just do what he said lol

Btw I can’t do anything fancy cuz I’m on mobile lol

I don’t want it to be random teams cuz there are teams for trainers, hosts, etc. @Plasmacticus

(S)He has a table with team instances so u don’t need to worry abt that

could you be more clear? the code i wrote basically makes it so that if a player with a certain rank in a group says !splitteam then it will make everybody in the trainee team go to a random team within the table of random teams. i dont understand what you mean

Oh, I didn’t read it carefully. Oops!

It’s ok. I didn’t read it carefully enough.

There are red lines when i add the teams into the table. @Plasmacticus

The team have to exist in order for them to be added
Edit: He forgot commas :confused:

1 Like

did you set the group id and the rank before it? it could be from those not being set first

local randomTeams = {
    -- put the teams here. examples below

as @Pure_Bacn said i forgot the commas so whoops

I did set those. I figured it out tho. Also, what does it mean by trainee teams

it’s the team you talked about in the first post. everyone in that team will get assigned to the random teams

In groups each rank have a number indicating it’s power.
So just put the power value of the rank in there.

Wait nvm I got a misread AGAIN

Do you know how to integrate that with Basic Admin Essential using their plugin thing?

Additionally, could the command change your overhead nametag instead of teaming you? @Plasmacticus