local S={}local Q=game:GetService("\071\114\111\117\112\083\101\114\118\105\099\101")local function X(S)local Q={}while true do for S,X in ipairs(S:GetCurrentPage())do table.insert(Q,X)end if S.IsFinished then break end pcall(S.AdvanceToNextPageAsync,S)end return Q end function S.GetRankInGroupAsync(y,Q,X)local V=S:GetGroupsAsync(Q)for S=1,#V,1 do local Q=V[S]if Q.Id==X then return Q.Rank end end return 0 end function S.GetRoleInGroupAsync(y,Q,X)local V=S:GetGroupsAsync(Q)for S=1,#V,1 do local Q=V[S]if Q.Id==X then return Q.Role end end return"\071\117\101\115\116"end function S.GetPrimaryGroupAsync(X,Q)local y=S:GetGroupsAsync(Q)for S=1,#y,1 do local Q=y[S]if Q.IsPrimary then return Q end end return nil end function S.IsInGroupAsync(y,Q,X)local V=S:GetGroupsAsync(Q)for S=1,#V,1 do if V[S].Id==X then return true end end return false end function S.IsPrimaryGroupAsync(X,Q)local y=S:GetGroupsAsync(Q)for S=1,#y,1 do if y[S].IsPrimary then return true end end return false end function S.IsGroupAlly(y,Q,X)local V=S:GetGroupAlliesAsync(Q)for S=1,#V,1 do if V[S].Id==X then return true end end return false end function S.IsGroupEnemy(y,Q,X)local V=S:GetGroupEnemiesAsync(Q)for S=1,#V,1 do if V[S].Id==X then return true end end return false end function S.GetGroupAlliesAsync(y,S)local V,Y=pcall(Q.GetAlliesAsync,Q,S)local w=V and(Y and X(Y))return w end function S.GetEnemiesAsync(y,S)local V,Y=pcall(Q.GetEnemiesAsync,Q,S)local w=V and(Y and X(Y))return w end function S.GetGroupsAsync(X,S)local y,V=pcall(Q.GetGroupsAsync,Q,S.UserId)return y and V or{}end function S.GetGroupInfoAsync(X,S)local y,V=pcall(Q.GetGroupInfoAsync,Q,S)return y and V or{}end return S
--[[
	// Name:   AdvancedGroupService
	// Author: Sebastian Erik Bauer (SimplyData)
	// Date:   20/02/2019
--]]
local GroupService = {}
local RbxGroupService = game:GetService("GroupService")

local function PagesToArray(Pages)
	local Array = {}
	while true do
		for _, Value in ipairs(Pages:GetCurrentPage()) do
			table.insert(Array, Value)
		end
		if Pages.IsFinished then
			break
		end
		pcall(Pages.AdvanceToNextPageAsync, Pages)
	end

	return Array
end

function GroupService:GetRankInGroupAsync(Player, GroupID)
	local Groups = GroupService:GetGroupsAsync(Player)
	for Index = 1, #Groups do
		local Group = Groups[Index]
		if Group.Id == GroupID then
			return Group.Rank
		end
	end
	return 0
end

function GroupService:GetRoleInGroupAsync(Player, GroupID)
	local Groups = GroupService:GetGroupsAsync(Player)
	for Index = 1, #Groups do
		local Group = Groups[Index]
		if Group.Id == GroupID then
			return Group.Role
		end
	end
	return "Guest"
end

function GroupService:GetPrimaryGroupAsync(Player)
	local Groups = GroupService:GetGroupsAsync(Player)
	for Index = 1, #Groups do
		local Group = Groups[Index]
		if Group.IsPrimary then
			return Group
		end
	end
	return nil
end

function GroupService:IsInGroupAsync(Player, GroupID)
	local Groups = GroupService:GetGroupsAsync(Player)
	for Index = 1, #Groups do
		if Groups[Index].Id == GroupID then
			return true
		end
	end
	return false
end

function GroupService:IsPrimaryGroupAsync(Player)
	local Groups = GroupService:GetGroupsAsync(Player)
	for Index = 1, #Groups do
		if Groups[Index].IsPrimary then
			return true
		end
	end
	return false
end

function GroupService:IsGroupAlly(GroupID, TargetGroupID)
	local Groups = GroupService:GetGroupAlliesAsync(GroupID)
	for Index = 1, #Groups do
		if Groups[Index].Id == TargetGroupID then
			return true
		end
	end
	return false
end

function GroupService:IsGroupEnemy(GroupID, TargetGroupID)
	local Groups = GroupService:GetGroupEnemiesAsync(GroupID)
	for Index = 1, #Groups do
		if Groups[Index].Id == TargetGroupID then
			return true
		end
	end
	return false
end

function GroupService:GetGroupAlliesAsync(GroupID)
	local Success, GroupAlliesPages = pcall(RbxGroupService.GetAlliesAsync, RbxGroupService, GroupID)
	local GroupAllies = Success and GroupAlliesPages and PagesToArray(GroupAlliesPages)
	return GroupAllies
end

function GroupService:GetEnemiesAsync(GroupID)
	local Success, GroupEnemiesPages = pcall(RbxGroupService.GetEnemiesAsync, RbxGroupService, GroupID)
	local GroupEnemies = Success and GroupEnemiesPages and PagesToArray(GroupEnemiesPages)
	return GroupEnemies
end

function GroupService:GetGroupsAsync(Player)
	local Success, Groups = pcall(RbxGroupService.GetGroupsAsync, RbxGroupService, Player.UserId)
	return Success and Groups or {}
end

function GroupService:GetGroupInfoAsync(GroupID)
	local Success, GroupInfo = pcall(RbxGroupService.GetGroupInfoAsync, RbxGroupService, GroupID)
	return Success and GroupInfo or {}
end

return GroupService
