How do I add multiple rank IDs to a Script?

So, I have made my own VIP BillBoardGui system. I have used Player:GetRankInGroup and it works fine. The only thing that I need, is I want to add multiple ranks to my if statement. Is there any way to do this and if so how? I will leave a photo below of the script.

Script:

Oh god, he’s not using dark mode!

Make GroupID variable a table, and insert Group Id’s of your choice in there.
And then on PlayerAdded, go through the table, and add a if statement for specific Group Id’s, and do whatever for them.

Are you able to write this out for me? I know what a table is, I just haven’t used them often.

You’ll have to give me the code of the script, because well, I am too lazy to copy the code from the image in order to type your solution.

local BillBoardGUI = game:GetService("ServerStorage"):WaitForChild("VIPOverHeadUI")

local GroupID = 8123401

game.Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function(character)
	
	if player:GetRankInGroup(GroupID) == 100 then
		
		local clonedgui = BillBoardGUI:Clone()
		clonedgui.TextLabel.Text = "VIP"
		clonedgui.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 0)
		clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
	end
 end)

end)

I do not know why it put the script like this. Please forgive me.

Can’t you just add or to the if statement?

1 Like

Use a table/dictionary and generalize it. There’s no need to have a big if elseif elseif else chain if you can do a for loop to iterate over a table. You could do something like:

local groups = {
    [groupId]=rankNumber,
    [groupId2]=rankNumber2,
    [groupId3]=rankNumber3
}

replacing the ids with their actual ids then you can:

for gId, rId in pairs(groups) do
    if player:GetRankInGroup(gId) == rId then
        -- ... code here
        break
    end
end
local BillBoardGUI = game:GetService("ServerStorage"):WaitForChild("VIPOverHeadUI")
local GroupID = {8123401,0} -- 0 is a temporary second groupid, for an example.

game.Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function(character)
	
	for _,id in next,GroupID do
       if id = 8123401 then
            if player:GetRankInGroup(id) == 100 then -- Copy and pasted this part.
		
		local clonedgui = BillBoardGUI:Clone()
		clonedgui.TextLabel.Text = "VIP"
		clonedgui.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 0)
		clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
	end
       end
    end
 end)
end)

But what if in the same group, the rank id is the same, meaning both groups have that rank id taken, and the player was accidentally given “VIP”?

Also, it’s for multiple group ID’s, break is not needed.

I am meaning for multiple group ranks. Sorry, I worded this wrong.

You don’t need to clone the gui to someone many times, if they’re vip, they’re vip so break is required. Second it only checks each groupId to it’s respective rankId so there is no worry about group ids and rank ids messing up

Example:

a group with id 1 directly relates to rank id 2, a group with id 5 directly relates to rank id 6 and a group with id 3 directly relates to rank id 4

1 Like

@Obj_ective Is it different for doing this with multiple group ranks but the same group ID?

But then wouldn’t that ruin the purpose of the code? that’s basically doing the same thing as the normalized version of the code

The original question was worded wrong apparently

1 Like

What do you mean?

If you mean for each group with a different RankId, then yes that if statement is needed.
If it’s for one group, then stick to the code you’ve started with.

If you want it for groups, but with the same RankId, then maybe.

I want to have the same group, but multiple ranks get the UI above their heads.

I guess steven was right, oops.
Well, in that case, this is your solution.

local BillBoardGUI = game:GetService("ServerStorage"):WaitForChild("VIPOverHeadUI")
local GroupID = 8123401

game.Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function(character)
	
	if player:GetRankInGroup(GroupID) == 100 then
		
		local clonedgui = BillBoardGUI:Clone()
		clonedgui.TextLabel.Text = "VIP"
		clonedgui.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 0)
		clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
	end
        if player:GetRankInGroup(GroupID) == 100 then -- Copy and paste, but change the number.
		
		local clonedgui = BillBoardGUI:Clone()
		clonedgui.TextLabel.Text = "VIP"
		clonedgui.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 0)
		clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
	end
 end)

So like this?

Yes.

If something goes wrong though, it’s where you’re pasting the code, for example you wanted it inside CharacterAdded, then paste it in there.

If that’s not the issue, then something is wrong within that code block.