GroupService

Show Deprecated
Not Creatable
Service
Not Replicated

GroupService is a service that allows developers to fetch information about a Roblox group from within a game.

Basic information on the group, including it's name, description, owner, roles and emblem can be fetched using GroupService:GetGroupInfoAsync(). Lists of a group's allies and enemies can be fetched using GroupService:GetAlliesAsync() and GroupService:GetEnemiesAsync().

GroupService can also be used to fetch a list of group's a player is a member of, using GroupService:GetGroupsAsync(). Note, developers wishing to verify if a player is in a group should use the Player Player:IsInGroup() function rather than GroupService:GetGroupsAsync().

The service has a number of useful applications, such as detecting if a player is an ally or enemy upon joining the game.

Code Samples

Group Ally/Enemy Checker

1local GroupService = game:GetService("GroupService")
2local Players = game:GetService("Players")
3
4-- define group id here
5local GROUP_ID = 271454
6
7-- utility function for dealing with pages
8local function pagesToArray(pages)
9 local array = {}
10 while true do
11 for _, v in ipairs(pages:GetCurrentPage()) do
12 table.insert(array, v)
13 end
14 if pages.IsFinished then
15 break
16 end
17 pages:AdvanceToNextPageAsync()
18 end
19 return array
20end
21
22-- get lists of allies and enemies
23local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
24local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
25
26-- convert to array
27local allies = pagesToArray(alliesPages)
28local enemies = pagesToArray(enemiesPages)
29
30local function playerAdded(player)
31 -- check to see if the player is in the group
32 if player:IsInGroup(GROUP_ID) then
33 print(player.Name .. " is a member!")
34 else
35 local isAlly, isEnemy = false, false
36
37 -- check to see if the player is in any ally groups
38 for _, groupInfo in ipairs(allies) do
39 local groupId = groupInfo.Id
40 if player:IsInGroup(groupId) then
41 isAlly = true
42 break
43 end
44 end
45
46 -- check to see if the player is in any enemy groups
47 for _, groupInfo in ipairs(enemies) do
48 local groupId = groupInfo.Id
49 if player:IsInGroup(groupId) then
50 isEnemy = true
51 break
52 end
53 end
54
55 if isAlly and not isEnemy then
56 print(player.Name .. " is an ally!")
57 elseif isEnemy and not isAlly then
58 print(player.Name .. " is an enemy!")
59 elseif isEnemy and isAlly then
60 print(player.Name .. " is both an ally and an enemy!")
61 else
62 print(player.Name .. " is neither an ally or an enemy!")
63 end
64 end
65end
66
67-- listen for new players being added
68Players.PlayerAdded:Connect(playerAdded)
69
70-- handle players already in game
71for _, player in ipairs(Players:GetPlayers()) do
72 playerAdded(player)
73end

Summary

Properties

Events

Methods

GetAlliesAsync(groupId: number): StandardPages  YIELDS

Returns a StandardPages object including information on all of the specified group's allies.

GetEnemiesAsync(groupId: number): StandardPages  YIELDS

Returns a StandardPages object including information on all of the specified group's enemies.

GetGroupInfoAsync(groupId: number): Variant  YIELDS

Returns a table containing information about the given group.

GetGroupsAsync(userId: number): Array  YIELDS

Returns a list of tables containing information on all of the groups a given player is a member of.

Properties

Events

Methods

GetAlliesAsync

Yields

Returns a StandardPages object including information on all of the specified group's allies.

This pages does not include a list of group IDs but instead a list of group information tables, mirroring the format of those returned by GroupService:GetGroupInfoAsync(). See below for the structure of these tables.


1group = {
2 Name = "Knights of the Seventh Sanctum",
3 Id = 377251,
4 Owner = {
5 Name = "Vilicus",
6 Id = 23415609
7 },
8 EmblemUrl = "http://www.roblox.com/asset/?id=60428602",
9 Description = "We fight alongside the balance to make sure no one becomes to powerful",
10 Roles = {
11 [1] = {
12 Name = "Apprentice",
13 Rank = 1
14 },
15 [2] = {
16 Name = "Warrior",
17 Rank = 2
18 },
19 [3] = {
20 Name = "Earth Walker",
21 Rank = 255
22 }
23 }
24}
25

Note, as this function returns a StandardPages object rather than an array, developers may wish to convert it to an array for ease of use (see examples).

This function has a number of useful applications, including detecting if a player is a member of an allied group.

For enemies, use GroupService:GetEnemiesAsync().

Parameters

groupId: number

The group's ID.


Code Samples

Group Ally/Enemy Checker

1local GroupService = game:GetService("GroupService")
2local Players = game:GetService("Players")
3
4-- define group id here
5local GROUP_ID = 271454
6
7-- utility function for dealing with pages
8local function pagesToArray(pages)
9 local array = {}
10 while true do
11 for _, v in ipairs(pages:GetCurrentPage()) do
12 table.insert(array, v)
13 end
14 if pages.IsFinished then
15 break
16 end
17 pages:AdvanceToNextPageAsync()
18 end
19 return array
20end
21
22-- get lists of allies and enemies
23local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
24local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
25
26-- convert to array
27local allies = pagesToArray(alliesPages)
28local enemies = pagesToArray(enemiesPages)
29
30local function playerAdded(player)
31 -- check to see if the player is in the group
32 if player:IsInGroup(GROUP_ID) then
33 print(player.Name .. " is a member!")
34 else
35 local isAlly, isEnemy = false, false
36
37 -- check to see if the player is in any ally groups
38 for _, groupInfo in ipairs(allies) do
39 local groupId = groupInfo.Id
40 if player:IsInGroup(groupId) then
41 isAlly = true
42 break
43 end
44 end
45
46 -- check to see if the player is in any enemy groups
47 for _, groupInfo in ipairs(enemies) do
48 local groupId = groupInfo.Id
49 if player:IsInGroup(groupId) then
50 isEnemy = true
51 break
52 end
53 end
54
55 if isAlly and not isEnemy then
56 print(player.Name .. " is an ally!")
57 elseif isEnemy and not isAlly then
58 print(player.Name .. " is an enemy!")
59 elseif isEnemy and isAlly then
60 print(player.Name .. " is both an ally and an enemy!")
61 else
62 print(player.Name .. " is neither an ally or an enemy!")
63 end
64 end
65end
66
67-- listen for new players being added
68Players.PlayerAdded:Connect(playerAdded)
69
70-- handle players already in game
71for _, player in ipairs(Players:GetPlayers()) do
72 playerAdded(player)
73end
GroupService:GetAlliesAsync

1local Players = game:GetService("Players")
2local GroupService = game:GetService("GroupService")
3
4local GROUP_ID = 57
5
6-- creates a table of all of the allies of a given group
7local allies = {}
8
9local pages = GroupService:GetAlliesAsync(GROUP_ID)
10
11while true do
12 for _, group in pairs(pages:GetCurrentPage()) do
13 table.insert(allies, group)
14 end
15 if pages.IsFinished then
16 break
17 end
18 pages:AdvanceToNextPageAsync()
19end
20
21function onPlayerAdded(player)
22 for _, group in pairs(allies) do
23 if player:IsInGroup(group.Id) then
24 print("Player is an ally!")
25 break
26 end
27 end
28end
29
30Players.PlayerAdded:Connect(onPlayerAdded)
31-- handle players who joined while the allies list was still loading
32for _, player in pairs(Players:GetPlayers()) do
33 onPlayerAdded(player)
34end

GetEnemiesAsync

Yields

Returns a StandardPages object including information on all of the specified group's enemies.

This pages does not include a list of group IDs but instead a list of group information tables, mirroring the format of those returned by GroupService:GetGroupInfoAsync(). See below for the structure of these tables.


1group = {
2 Name = "Knights of the Seventh Sanctum",
3 Id = 377251,
4 Owner = {
5 Name = "Vilicus",
6 Id = 23415609
7 },
8 EmblemUrl = "http://www.roblox.com/asset/?id=60428602",
9 Description = "We fight alongside the balance to make sure no one becomes to powerful",
10 Roles = {
11 [1] = {
12 Name = "Apprentice",
13 Rank = 1
14 },
15 [2] = {
16 Name = "Warrior",
17 Rank = 2
18 },
19 [3] = {
20 Name = "Earth Walker",
21 Rank = 255
22 }
23 }
24}
25

Note, as this function returns a StandardPages object rather than an array, developers may wish to convert it to an array for ease of use (see examples).

This function has a number of useful applications, including detecting if a player is a member of an enemy group.

For allies, use GroupService:GetAlliesAsync().

Parameters

groupId: number

The group's ID.


Code Samples

GroupService:GetEnemiesAsync

1local Players = game:GetService("Players")
2local GroupService = game:GetService("GroupService")
3
4local GROUP_ID = 57
5
6-- creates a list of all of the enemies of a given group
7local enemies = {}
8
9local pages = GroupService:GetEnemiesAsync(GROUP_ID)
10
11while true do
12 for _, group in pairs(pages:GetCurrentPage()) do
13 table.insert(enemies, group)
14 end
15 if pages.IsFinished then
16 break
17 end
18 pages:AdvanceToNextPageAsync()
19end
20
21function onPlayerAdded(player)
22 for _, enemyGroup in pairs(enemies) do
23 if player:IsInGroup(enemyGroup.Id) then
24 print("Player is an enemy!")
25 break
26 end
27 end
28end
29
30Players.PlayerAdded:Connect(onPlayerAdded)
31-- handle players who joined while the enemies list was still loading
32for _, player in pairs(Players:GetPlayers()) do
33 onPlayerAdded(player)
34end
Group Ally/Enemy Checker

1local GroupService = game:GetService("GroupService")
2local Players = game:GetService("Players")
3
4-- define group id here
5local GROUP_ID = 271454
6
7-- utility function for dealing with pages
8local function pagesToArray(pages)
9 local array = {}
10 while true do
11 for _, v in ipairs(pages:GetCurrentPage()) do
12 table.insert(array, v)
13 end
14 if pages.IsFinished then
15 break
16 end
17 pages:AdvanceToNextPageAsync()
18 end
19 return array
20end
21
22-- get lists of allies and enemies
23local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
24local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
25
26-- convert to array
27local allies = pagesToArray(alliesPages)
28local enemies = pagesToArray(enemiesPages)
29
30local function playerAdded(player)
31 -- check to see if the player is in the group
32 if player:IsInGroup(GROUP_ID) then
33 print(player.Name .. " is a member!")
34 else
35 local isAlly, isEnemy = false, false
36
37 -- check to see if the player is in any ally groups
38 for _, groupInfo in ipairs(allies) do
39 local groupId = groupInfo.Id
40 if player:IsInGroup(groupId) then
41 isAlly = true
42 break
43 end
44 end
45
46 -- check to see if the player is in any enemy groups
47 for _, groupInfo in ipairs(enemies) do
48 local groupId = groupInfo.Id
49 if player:IsInGroup(groupId) then
50 isEnemy = true
51 break
52 end
53 end
54
55 if isAlly and not isEnemy then
56 print(player.Name .. " is an ally!")
57 elseif isEnemy and not isAlly then
58 print(player.Name .. " is an enemy!")
59 elseif isEnemy and isAlly then
60 print(player.Name .. " is both an ally and an enemy!")
61 else
62 print(player.Name .. " is neither an ally or an enemy!")
63 end
64 end
65end
66
67-- listen for new players being added
68Players.PlayerAdded:Connect(playerAdded)
69
70-- handle players already in game
71for _, player in ipairs(Players:GetPlayers()) do
72 playerAdded(player)
73end

GetGroupInfoAsync

Yields

Returns a table containing information about the given group.

The table returned is the same format as that returned in GroupService:GetAlliesAsync() and GroupService:GetEnemiesAsync(). This format can be seen below.


1group = {
2 Name = "Knights of the Seventh Sanctum",
3 Id = 377251,
4 Owner = {
5 Name = "Vilicus",
6 Id = 23415609
7 },
8 EmblemUrl = "http://www.roblox.com/asset/?id=60428602",
9 Description = "We fight alongside the balance to make sure no one becomes to powerful",
10 Roles = {
11 [1] = {
12 Name = "Apprentice",
13 Rank = 1
14 },
15 [2] = {
16 Name = "Warrior",
17 Rank = 2
18 },
19 [3] = {
20 Name = "Earth Walker",
21 Rank = 255
22 }
23 }
24}
25

Note, if a group has no owner the Owner field will be set to nil.

This function has a number of useful applications, including loading the latest description and logo of a group for display in a group base.

Parameters

groupId: number

The group ID of the group.


Returns

A dictionary of information about the group.

Code Samples

Load Group Emblem

1local GroupService = game:GetService("GroupService")
2
3local function getEmblemAsync(groupId)
4 local groupInfo = GroupService:GetGroupInfoAsync(groupId)
5 return groupInfo.EmblemUrl
6end
7
8local part = Instance.new("Part")
9part.Anchored = true
10part.CanCollide = false
11part.Size = Vector3.new(5, 5, 1)
12part.Position = Vector3.new(0, 5, 0)
13
14local decal = Instance.new("Decal")
15decal.Parent = part
16part.Parent = workspace
17
18decal.Texture = getEmblemAsync(377251)
GroupService:GetGroupInfoAsync

1local GroupService = game:GetService("GroupService")
2
3local GROUP_ID = 377251
4
5local group = GroupService:GetGroupInfoAsync(GROUP_ID)
6
7print(group.Name .. " has the following roles:")
8for _, role in ipairs(group.Roles) do
9 print("Rank " .. role.Rank .. ": " .. role.Name)
10end

GetGroupsAsync

Yields

Warning: The IsInClan property in the returned table will always return false and exists for backwards compatibility. The Clans feature was sunset from the Roblox platform in 2016.

This function returns a list of tables containing information on all of the groups a given Player is a member of.

The list returned will include an entry for every group the player is a member of. These entries are tables with the following fields.

NameDescription
NameThe group's name
IdThe group ID
EmblemUrlAn asset url linking to the group's thumbnail (for example: http://www.roblox.com/asset/?id=276165514)
EmblemIdThe assetId of the emblem, the same which is used in the EmblemUrl
RankThe rankId the player has (for example: 255 for the owner)
RoleThe name of the player's grouprank (for example: Group Owner)
IsPrimaryA boolean indicating if this is the player's primary group
IsInClanA boolean indicating if the player is in this group's clan

Note unlike GroupService:GetAlliesAsync() and GroupService:GetEnemiesAsync(), GetGroupsAsync returns a table rather than a StandardPages object.

Parameters

userId: number

The Player.UserId of the user.


Returns

An array of dictionaries containing information on the group's the Player is a member of.

Code Samples

Getting the Groups that a User is A Member Of

1local GroupService = game:GetService("GroupService")
2local Players = game:GetService("Players")
3
4local function playerAdded(player)
5 -- load a list of info on all groups the player is a member of
6 local groups = GroupService:GetGroupsAsync(player.UserId)
7
8 for _, groupInfo in pairs(groups) do
9 for key, value in pairs(groupInfo) do
10 print(key .. ": " .. tostring(value))
11 end
12
13 print("--")
14 end
15end
16
17Players.PlayerAdded:Connect(playerAdded)
18
19-- go through existing players
20for _, player in pairs(Players:GetPlayers()) do
21 playerAdded(player)
22end