Teaming by group rank doesnt work

So, I want to make script that makes you join team automatically bases on your group rank. When I test game, it just joins me to random team.

Heres script:

local Visitorst = game:GetService("Teams"):WaitForChild("Visitors")
local LowRankt = game:GetService("Teams"):WaitForChild("Low Ranks")
local MiddleRankt = game:GetService("Teams"):WaitForChild("Middle Ranks")
local HighRankt = game:GetService("Teams"):WaitForChild("High Ranks")
local SeniorHighRankt = game:GetService("Teams"):WaitForChild("Senior High Ranks")
local HeadOfficet = game:GetService("Teams"):WaitForChild("Head Office")
local Ownershipt = game:GetService("Teams"):WaitForChild("Ownership Team")

local groupID = 16522602

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		if player:IsInGroup(groupID) then
			local playerank = player:GetRankInGroup(groupID)
			
			if playerank >= 253 then
				player.Team = Ownershipt
				
			elseif playerank >= 247 and not (playerank >= 253) then
				player.Team = HeadOfficet
				
			elseif playerank >= 243 and not (playerank >= 247) then
				player.Team = SeniorHighRankt
				
			elseif playerank >= 236 and not (playerank >= 243) then
				player.Team = HighRankt
				
			elseif playerank >= 225 and not (playerank >= 236)  then
				player.Team = MiddleRankt
				
			elseif playerank >= 115 and not (playerank >= 225)  then
				player.Team = LowRankt
				
			elseif playerank >= 1 and not (playerank >= 115) then
				player.Team = Visitorst
			end
		end
	end)
end)

It gives me no error, can someone help me?

1 Like

Firstly, I’d recommend changing this

to

local Teams = game:GetService("Teams")
local Visitorst = Teams:WaitForChild("Visitors")
... -- Same for all of them

Have you tried printing the rank of the user? I’ve had troubles with this in studio sometimes.

Also,

This (and not (playerank >= X)) isn’t needed, since you will only reach that condition if it wasn’t larger than that

Yes, I tried printing the rank and it worked. Let me try things you wrote

Isnt working, still teaming me to random teams

local Visitorst = game:GetService("Teams"):WaitForChild("Visitors")
local LowRankt = game:GetService("Teams"):WaitForChild("Low Ranks")
local MiddleRankt = game:GetService("Teams"):WaitForChild("Middle Ranks")
local HighRankt = game:GetService("Teams"):WaitForChild("High Ranks")
local SeniorHighRankt = game:GetService("Teams"):WaitForChild("Senior High Ranks")
local HeadOfficet = game:GetService("Teams"):WaitForChild("Head Office")
local Ownershipt = game:GetService("Teams"):WaitForChild("Ownership Team")

local groupID = 16522602

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		local playerank = player:GetRankInGroup(groupID)

		if playerank >= 253 then
			player.Team = Ownershipt
		elseif playerank >= 247 then
			player.Team = HeadOfficet
		elseif playerank >= 243 then
			player.Team = SeniorHighRankt
		elseif playerank >= 236 then
			player.Team = HighRankt
		elseif playerank >= 225 then
			player.Team = MiddleRankt
		elseif playerank >= 115 then
			player.Team = LowRankt
		elseif playerank >= 1 then
			player.Team = Visitorst
		end
	end)
end)

Try this and tell me if work.

So it prints a correct number… Try adding prints inside the if-statements. It looks OK to me, but obviously something isn’t right

These checks are not necessary because the conditions of the if and elseif statements are already mutually exclusive. :smirk:

Doesnt work

asdsadsadsadasdasd

I put print in every statement. Only one thing printed while there should be 7

Only one should print, the team you get put into should be the only one printing. Are you able to send the updated code as well as the prints? (including your rank print)

local Teams = game:GetService("Teams")
local Visitorst = Teams:WaitForChild("Visitors")
local LowRankt = Teams:WaitForChild("Low Ranks")
local MiddleRankt = Teams:WaitForChild("Middle Ranks")
local HighRankt = Teams:WaitForChild("High Ranks")
local SeniorHighRankt = Teams:WaitForChild("Senior High Ranks")
local HeadOfficet = Teams:WaitForChild("Head Office")
local Ownershipt = Teams:WaitForChild("Ownership Team")

local groupID = 16522602

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		local playerank = player:GetRankInGroup(groupID)

		if playerank >= 253 then
			player.Team = Ownershipt
		elseif playerank >= 247 then
			player.Team = HeadOfficet
			print("Hello world")
		elseif playerank >= 243 then
			player.Team = SeniorHighRankt
		elseif playerank >= 236 then
			player.Team = HighRankt
		elseif playerank >= 225 then
			player.Team = MiddleRankt
		elseif playerank >= 115 then
			player.Team = LowRankt
		elseif playerank >= 1 then
			player.Team = Visitorst
		end
	end)
end)

From those 7 I put earlier only that with what team I should get worked and printed.

Probably because you put >= instead of ==?

No, I script ranks for water park group and there are Low Ranks etc

Well yeah, but isn’t it changing your team to random ones?

Even that I changed to ==, it is still teaming me to random

I just tested this and it seems to be working fine. Are you sure that you saved it?
Here’s the code I used:
local Visitorst = game:GetService(“Teams”):WaitForChild(“Visitors”)
local LowRankt = game:GetService(“Teams”):WaitForChild(“Low Ranks”)
local MiddleRankt = game:GetService(“Teams”):WaitForChild(“Middle Ranks”)
local HighRankt = game:GetService(“Teams”):WaitForChild(“High Ranks”)
local SeniorHighRankt = game:GetService(“Teams”):WaitForChild(“Senior High Ranks”)
local HeadOfficet = game:GetService(“Teams”):WaitForChild(“Head Office”)
local Ownershipt = game:GetService(“Teams”):WaitForChild(“Ownership Team”)

local groupID = 16522602

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
if player:IsInGroup(groupID) then
local playerank = player:GetRankInGroup(groupID)

        if playerank >= 253 then
            player.Team = Ownershipt
            
        elseif playerank >= 247 and not (playerank >= 253) then
            player.Team = HeadOfficet
            
        elseif playerank >= 243 and not (playerank >= 247) then
            player.Team = SeniorHighRankt
            
        elseif playerank >= 236 and not (playerank >= 243) then
            player.Team = HighRankt
            
        elseif playerank >= 225 and not (playerank >= 236)  then
            player.Team = MiddleRankt
            
        elseif playerank >= 115 and not (playerank >= 225)  then
            player.Team = LowRankt
            
        elseif playerank >= 1 and not (playerank >= 115) then
            player.Team = Visitorst
        end
    end
end

I already fixed it somehow, but thanks