How can I print users with a minimum rank of 3 and above

Hey everyone! I’m trying to figure out how to make this print users who are rank 3 or above in a group. I would also want them to be seperated by a comma. How would I modify this code:

Note: This is just a part of the code.

for _, Player in pairs(game.Players:GetPlayers()) do
    print(Player.Name) -- Prints all players
end

Any help is appreciated, thanks!

1 Like

You can use Player:GetRankInGroup() to check a player’s rank in group. If the result is 0 then the player is not in the group:

for _, Player in pairs(game.Players:GetPlayers()) do
if Player:GetRankInGroup(groupid) >= 3 then
print(Player.Name)
end
end
1 Like

Is this possible to seperate each users’ names by a comma? For example: jees1, BenMactavsin, Player1

Try this:

local ATable={}
for _, Player in pairs(game.Players:GetPlayers()) do
    if Player:GetRankInGroup(groupid) >= 3 then
        table.insert(ATable,Player)
    end
end
if #ATable > 0 then
   print(table.concat(ATable,", "))
end

sorry, i just figured out it would not put commas before so i used table.concat

1 Like

You should probably turn it into a single string and build it up from there.

local printingString = ""
for _, Player in pairs(game.Players:GetPlayers()) do
    if Player:GetRankInGroup(groupid) >= 3 then
        if #printingString == 0 then
            printingString = printingString .. Player.Name 
        else
            printingString = printingString .. ", " .. Player.Name
        end
    end
end

print(printingString)

@Nube762 There are no separators in your code, it ends up with whitespaces in between. Does not quite give you the commas as written by @OP.

1 Like

Sorry for late response because I had to leave to do something else while writing this response. You can also do this if you don’t want to do the options above:

local result = ""
for _, Player in pairs(game.Players:GetPlayers()) do
    if Player:GetRankInGroup(groupid) >= 3 then
        result = result..", "..Player.Name
    end
end
result = string.sub(result,3,-1)
print(result)
1 Like