How can I print users what are part of a team

Hey everyone, I currently have this script to print users who are a specific rank in a group, though I now want to print users on a specific team, is that possible? Also, make sure it is seperated by a comma.

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)

Any help is appreciated, thanks!

Yes this is entirely possible. You just have to use Team:GetPlayers()
Hope this helps :slight_smile:

1 Like

Unless of course you mean specific Role in the group. In which case you just have to iterate through your Playeds in your game and attach GetRoleInGroup(). Then you can see the roles in the group.

Which part should I modify? I’m a bit confused here.
I want for the users to be seperated by a comma.

Did you click on and read the documentation? It outlines that Teams:GetPlayers() returns the players that are inside of a team. You have to input the team into the function.
The use would be like this.

local team = game:GetService(“Teams”).TeamName
local playersInTeam = team:GetPlayers()

And, as a rule. You aren’t allowed to ask for entire scripts here. We can help you out with scripting questions, but you will have to learn to code for yourself in order to grow. We are meant to flag posts that give away code without teaching anything.

I want to modify the script and not ask for a full, though am confused on how would I modify it from ranks to teams.
How do I specify the team name?

To print the players on two team you would do this:

local TeamsService = game:GetService("Teams")
local Team1 = TeamsService.NameOfTeam1 --change the NameOfTeam1 to the first team you have under the Teams Service.
local Team2 = TeamsService.NameOfTeam2--change the NameOfTeam2 to the second team you have under the Teams Service.

local Team1MembersString = "Members in the " .. Team1.Name .. "team: "
local Team2MembersString = "Members in the " .. Team2.Name .. "team: "

local function GetPlayersStringFromTeam(Team)
    local TeamSize = #Team:GetPlayers()
    local PlayersString = ""

    for Index, Player in ipairs(Team:GetPlayers()) do
        if (Index < TeamSize) then
            PlayersString = PlayersString .. Player.Name .. ","
        else
            PlayersString = PlayersString .. Player.Name
        end
    end

    return PlayersString 
end

Team1MembersString = Team1MembersString ..  GetPlayersStringFromTeam(Team1)
Team2MembersString = Team2MembersString ..  GetPlayersStringFromTeam(Team2)

Do you not have a team set up in your game yet? I’m confused if you saw it or not. But the part in the above code that says, TeamName, is where you put the literal name of your team.