Group Rank Team Script Not working

Hi, I’m trying to assign teams based off group ranks using a script. For some reason, this doesn’t work.

local rankToTeam = {
	--["Team color"] = {min, max}
	["Institutional white"] = {0, 4}, -- Hotel Guest - Awaiting Training
	["Parsley green"] = {6, 8}, --Low Ranks
	["Eggplant"] = {9, 11}, --Middle Ranks
	["Navy blue"] = {12, 14}, -- High Ranks
	["Neon orange"] = {15, 18}, -- Super High Ranks
	["Maroon"] = {19, 225} -- Owner
	
}

game.Players.PlayerAdded:Connect(function(plr)
	for teamColor, range in pairs(rankToTeam) do
		if range[1] <= plr:GetRankInGroup(5242079) and plr:GetRankInGroup(5242079) <= range[2] then
			plr.TeamColor = BrickColor.new(teamColor)
			return
		end
	end
end)

First off, you might want to make sure your conditions are being set properly.

Second off, assigning teams based on color isn’t a good idea at all. Try to change the code to incorporate the Player.Team property. The wiki also has a tutorial on assigning players to teams.

As for checking group roles, you have a good start on how to do that, but I would look at other posts made here as this question has been asked multiple times.

1 Like

I have that script

local groupId =
local TeamNames = {[" (team name) "] = " (group rank name) "} -- you can add more by putting  ,[" (team name) "] = " (group rank name) "
game:GetService("Players").PlayerAdded:Connect(function(player)
	player.Team = game:GetService("Teams")[TeamNames[player:GetRoleInGroup(groupId)]]
end)

Tell me if this works for you

1 Like

Thanks, I found the error. I’ll use the Player.Team property script as given by bonejon

That gives a local error:
image

What are you putting this in? It needs to be in a ServerScriptService

It is in ServerScriptService. Looks like a code error.

Ok just do

local TeamNames = {[" (team name) "] = " (group rank name) "} -- you can add more by putting  ,[" (team name) "] = " (group rank name) "
game:GetService("Players").PlayerAdded:Connect(function(player)
	player.Team = game:GetService("Teams")[TeamNames[player:GetRoleInGroup(GROUPID)]] -- change GROUPID to your group id
end)
1 Like

did the script work like it is supposed to?

Still, nope, something’s not properly working.

did you put in the team name and the group rank name? also did you put in your group id?
Also did you spell them correctly?