Basically, using a server script, I want to get all of the enemies of a group. I found out that there was a way to do this: A game service called GroupService had a method called GetEnemiesAsync. I looked up the documentation for GetEnemiesAsync on the Wiki, and it said that it returned an object called Pages. However, the article didn't make it clear how I was to retrieve data from the Pages.
How do I get data from the Pages object?
In the case of the GetEnemiesAsync function, it will return a Pages instance which is essentially just an array of pages that have all the enemy groups of that particular group on it. To advance to the next page, you can use the the function AdvanceToNextPageAsync. Here is an example on how to check to see if a particular group is an enemy of another.
function checkIfEnemy(group, enemyGroup) local pages = game:GetService("GroupService"):GetEnemiesAsync(group) local isEnemy = false while true do for _, group in pairs(pages:GetCurrentPage()) do if group.Id == enemyGroup then isEnemy = true end end if pages.IsFinished then break end pages:AdvanceToNextPageAsync() end return isEnemy end print(checkIfEnemy(28, 131688)) -- Output : true print(checkIfEnemy(28, 100)) -- Output : false
The main thing to point out here is that a Pages object is an array of pages and each page has groups on it. Here is a example of what the layout of one of these groups would look like.
local group = { Name = "Knights of the Seventh Sanctum "; Id = 377251; Owner = { Name = "Vilicus"; Id = 23415609; }; EmblemUrl = "http://www.roblox.com/asset/?id=60428602"; Description = "We fight alongside the balance to make sure no one becomes to powerful. For guidance we look to the Earth as there is nothing more pure. "; Roles = { { Name = "Apprentice"; Rank = 1; }, { Name = "Warrior"; Rank = 2; }, { Name = "Earth Walker"; Rank = 255; } }; }
Knowing this you could rip apart the group piece by piece. Say you want the Description of the group, you'd simple use the line group.Description
.