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
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
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.
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)