AutoTeam Group Rank

So, I have this code that auto teams you once you join the game based on your rank in my group. For some reason it is not working, I am looking for assistance to fix it. I will provide a screenshot below of the code.

Image:

1 Like

Try something like this.

--// Variables //--
local GroupId = 00000

--// Functions //--
game.Players.PlayerAdded:Connect(function(Player)
    if Player:GetRankInGroup(GroupId) == 255 then
        Player.Team = game.Teams["NAME OF TEAM HERE"]
    end
end)

Hope it works

Are you trying to team specific ranks or ranges of ranks?

If I was to add multiple group ranks to it, would I do it like this?

Image:

I’m pretty sure, yes. [30charcharchar]

No it wouldn’t. You have to add an elseif statement like you did with your previous code, the only change being the

Player.Team = game.Teams["YOUR TEAM NAME"] 

statement other than the

player.TeamColor

statement you put earlier.

No, just use elseif.

--// Variables //--
local GroupId = 00000

--// Functions //--
game.Players.PlayerAdded:Connect(function(Player)
    if Player:GetRankInGroup(GroupId) == 255 then
        Player.Team = game.Teams["NAME OF TEAM HERE"]
    elseif Player:GetRankInGroup(GroupId) == 111  then
        Player.Team = game.Teams["NAME OF TEAM HERE"]
    end
end)
2 Likes

If your’re wanting to team specific ranks, please use a Dictionary

local players = game:GetService("Players")

local ranksColors = {
	[254] = BrickColor.new("Black"),
	[250] = BrickColor.new("New Yeller"),
    --Add more if needed
}

local groupid = --Your group id

players.PlayerAdded:Connect(function(plr)
	local rank = plr:GetRankInGroup(groupid)
	
	local color = ranksColors[rank]
	
	if color then
		plr.Team.TeamColor = color
	end
end)

@BostonWhaIer Yours would work as well, but you wouldn’t really need to have an else if @OP sets the default team as AutoAssignable

2 Likes
local PlayerService = game:GetService("Players")

local groupID = 000000000

local groupTeamTable = {
	--[rank required] = the team
	[255] = game.Teams:WaitForChild("Administration");
	
}

-- each indice in the table is the team that the player will be added to.

PlayerService.PlayerAdded:Connect(function(player)
	local playerRank = player:GetRankInGroup(groupID)
	if groupTeamTable[playerRank] ~= nil then
		player.Team = groupTeamTable[playerRank]
	else
		-- just set the player's team to some default team
		
		player.Team = game.Teams["Default Team or something..."]
	end
end)

Something like this would work.

1 Like

So it would be like this?

Image:

Please use a dictionary, that amount of if statements is unholy. Use what either I or @BostonWhaIer suggested, it’s way more organized

1 Like

The people suggesting a dictionary are right. Also, the problem in your original screenshot is that you are using <= where you should use >=

2 Likes

But does the way I did it work?

Yes it will but please for the sake of you and others, organize it with a dictionary

1 Like