Teaming several group ranks to one team

I need script that will make several group ranks to automatically after joining team certain players, depending on their group rang to certain teams, anyone here has idea how to do that?

I have script, but it is not working for some reason, there is not any error in console or anything so I don’t know where is problem.

I tried googling for solution, but did not find it unfortunately.

Here is the script that i putted together:
(Disclaimer: I am not a scripter, I mainly build and make UIs)

-- Group = 5671098

function Added(plyr)
	-- NEM. CIV. --
	if plyr:GetRankInGroup(Group) == {2, 32, 33, 34, 35, 36, 37, 253} then 
		plyr.TeamColor = BrickColor.new("Dark stone grey")
	-- ČSR. CIV. --
elseif plyr:GetRankInGroup(Group) == {1, 6, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 252, 255}
	then plyr.TeamColor = BrickColor.new("Really black") 
	    end 
	end 

game.Players.PlayerAdded:connect(Added) 
	

Thanks for any help, I will be highly grateful.

2 Likes

You’ve been trying to compare the rank with a table. It would only return “true” if the left and right sides of the equation would be the same. You can do it this way:

-- Group = 5671098

function Added(plyr)
	-- NEM. CIV. --
	if plyr:GetRankInGroup(Group) == (2 or 32 or  33 or 34 or  35 or 36 or  37 or 253) then 
		plyr.TeamColor = BrickColor.new("Dark stone grey")
	-- ČSR. CIV. --
elseif plyr:GetRankInGroup(Group) == (1 or  6 or 39 or 40 or 41 or 42 or 43 or 44 or 45 or 46 or 47 or 48 or 49 or 50 or 51 or 52 or 53 or 54 or 252 or 255)
	then plyr.TeamColor = BrickColor.new("Really black") 
	    end 
	end 

game.Players.PlayerAdded:connect(Added) 

Although if I was you, I’d make a table handling the ranks and the teams they should be assigned to as well as using >= and <= functions to optimize the code.

1 Like

Put those 2 tables in separate variables and use table.find

Example

local tbl = {2, 32, 33} 

-- Later on
local rank = plyr:GetRankInGroup(group)

if table.find(tbl, rank) then
    -- Change team
end
1 Like

Thanks for reply, I copied the script but it is still unfortunately not working. Maybe you made some small mistake, as I am not scripter I cannot notice that, In code it underlined “Group” text.

Uncomment the “group” variable and make it an actual variable.

1 Like

i.e. change the line 1 over to:

local Group = 5671098

Hello and thanks for reply, can you please elaborate further on how do you mean it? I did not worked with tables before.

Right so, the way you have it right can’t work because you’d be comparing a number with a table, since you want to see if that number in the table, you need to use table.find

What table.find does is that it has 2 parameters, first one is the table and the 2nd is the element to find in the table. If the element is found it returns the index of where it is, other it returns nil

local tbl = {"Bread", "Butter", "Cheese"}

print(table.find(tbl, "Butter")) -- 2
print(table.find(tbl, "Hotdog")) -- nil

Luau treats nil as a false in if statements, so if it doesn’t find the thing in that table, it wont go inside the if statement.

Put the 2 tables you used in variables and use table.find instead of an equality check

2 Likes

If you wish to use this solution brought by @EmbatTheHybrid, which I would say, is more efficient than your current code, make a table or two that would handle rankIDs for different teams.

Specifically, you could do something like this:

local GroupId = 5671098

local Ranklock = {
[1] = {2, 32, 33, 34, 35, 36, 37, 253},
[2] = {1, 6, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 252, 255}
}

function AdjustTeam(Player)
   if table.find(Ranklock[1], Player:GetRankInGroup(GroupId)) then
      plr.TeamColor = BrickColor.new("Dark stone grey")
   elseif table.find(Ranklock[2], Player:GetRankInGroup(GroupId)) then
      plr.TeamColor = BrickColor.new("Really black")
   end
end

game.Players.PlayerAdded:Connect(AdjustTeam)
1 Like

Again thanks, but it seems there is again some small problem with the script.

Pardon me, I was in a hurry, replace plr with “Player”.

2 Likes
if Rank == 2 or (Rank > 31 and Rank < 38) or Rank == 253 then
	--Team1.
else
	--Team2.
end