Group rank team script won't put me in the correct team

So I am currently in the process of make a script where if you are a certain rank in a group it will put you in a certain team, but it doesn’t seem to be working.

How it should work:
If I am an HR (Chief Public Relations Officer - Group Holder) I should be in the team HR. (This should work for other teams.)

There is also nothing in the output.

Can anyone figure out on why it isn’t working and how to fix it?

Script if needed
game.ReplicatedStorage.TeamEvent.OnServerEvent:Connect(function(player, Team)
	
end)

if Team == "Guest" then
		player.TeamColor = game.Teams:FindFirstChild(Team).TeamColor	
		player:LoadCharacter()
	
elseif Team == "Customer" then
		if player:GetRankInGroup(4607825) == 228 then
			player.TeamColor = game.Teams:FindFirstChild(Team).TeamColor
			player:LoadCharacter()		
		end
	
elseif Team == "LR" then
				if player:GetRankInGroup(4607825) == 231 then
					player.TeamColor = game.Teams:FindFirstChild(Team).TeamColor
		player:LoadCharacter()
	end
	
elseif Team == "MR" then
	if player:GetRankInGroup(4607825) == 235 then
		player.TeamColor = game.Teams:FindFirstChild(Team).TeamColor
		player:LoadCharacter()
	end
	
elseif Team == "HR" then
	if player:GetRankInGroup(4607825) == 240 then
		player.TeamColor = game.Teams:FindFirstChild(Team).TeamColor
		player:LoadCharacter()
	end
end
1 Like

You didn’t put the if statements in the RemoteEvent

game.ReplicatedStorage.TeamEvent.OnServerEvent:Connect(function(player, Team)
	if Team == "Guest" then
		player.TeamColor = game.Teams:FindFirstChild(Team).TeamColor	
		player:LoadCharacter()
	elseif Team == "Customer" then
		if player:GetRankInGroup(4607825) == 228 then
			player.TeamColor = game.Teams:FindFirstChild(Team).TeamColor
			player:LoadCharacter()		
		end
	elseif Team == "LR" then
		if player:GetRankInGroup(4607825) == 231 then
			player.TeamColor = game.Teams:FindFirstChild(Team).TeamColor
			player:LoadCharacter()
		end
	elseif Team == "MR" then
		if player:GetRankInGroup(4607825) == 235 then
			player.TeamColor = game.Teams:FindFirstChild(Team).TeamColor
			player:LoadCharacter()
		end
		
	elseif Team == "HR" then
		if player:GetRankInGroup(4607825) == 240 then
			player.TeamColor = game.Teams:FindFirstChild(Team).TeamColor
			player:LoadCharacter()
		end
	end
end)
1 Like

You put the if statements outside the RemoteEvent, so the script will think the “Team” parameter is nil (and the “player” parameter).

I entered in the script but it’s still not putting me into the correct team. :thinking: (The team I should be in is HR.)

That’s probably something going on with what you’re firing into the event, may I see the localscript that fires the event?

Mh, I’m not very sure about this but try change

player.Team

with game.Players:FindFirstChild(player).Team

so if you want to rank everyone when they join, then scrap the remote events, all you need to do is this (script in server script service):

local Teams = game:GetService('Teams')
local Players = game:GetService('Players')
local GroupId = 4607825
local Ranks = {
    [228] = "Customer";
    [231] = "LR";
    [235] = "MR";
    [240] = "HR"
}
Players.PlayerAdded:Connect(function(Player)
      if not Player:IsInGroup(GroupId) then -- Assuming 'Guest' is a guy who didn't join the group, correct me if i'm wrong
            Player.TeamColor = Teams:WaitForChild('Guest')
      elseif Player:IsInGroup(GroupId) and Player:GetRankInGroup(GroupId) == 228 then
            Player.Team = Teams:WaitForChild(Ranks[228])
      elseif Player:IsInGroup(GroupId) and Player:GetRankInGroup(GroupId) == 231 then
            Player.Team = Teams:WaitForChild(Ranks[231])
      elseif Player:IsInGroup(GroupId) and Player:GetRankInGroup(GroupId) == 235 then
            Player.Team = Teams:WaitForChild(Ranks[235])
     elseif Player:IsInGroup(GroupId) and Player:GetRankInGroup(GroupId) == 240 then
            Player.Team = Teams:WaitForChild(Ranks[240])
      end
end)

I agree that if it’s just rank on join that it should just be a regular script in ServerScriptService, but your way doesn’t make it simple to add a new role team as you’d have use another elseif statement, which is already confusing to do as GetRankInGroup returns a number of their rank in the group, can’t you just give that in the Ranks dictionary? If it’s not in there it will just return nil, which can be used to check if you should continue or not.

I would personally do it like this

local Teams = game:GetService('Teams')
local Players = game:GetService('Players')
local GroupId = 4607825

local Ranks = {
    [228] = "Customer";
    [231] = "LR";
    [235] = "MR";
    [240] = "HR"
}

Players.PlayerAdded:Connect(function(Player)

	if not Player:IsInGroup(GroupId) then
		Player.TeamColor = Teams["Guest"].TeamColor
		Player:LoadCharacter()
		return
	end

	local rank = Ranks[Player:GetRankInGroup(GroupId)]
	
	if not rank then return end
	
	Player.Team = Teams[rank]
	Player:LoadCharacter()
end)

When a player joins, it checks if they are in the group, if they aren’t, make their TeamColor the same as the Guest team and respawn them and return the event so it wont continue on with the code for if they are in the group.

Then it checks if there’s a key in that dictionary using their rank in the group, and if there isn’t anything, don’t continue. If there is, change their team and respawn them. This only requires you to add a new thing in that dictionary

1 Like

lol. Didn’t think of that!..