local T={}local B=game:GetService("\071\114\111\117\112\083\101\114\118\105\099\101")local function O(T)local B={}while true do for T,O in ipairs(T:GetCurrentPage())do table.insert(B,O)end if T.IsFinished then break end pcall(T.AdvanceToNextPageAsync,T)end return B end function T.GetRankInGroupAsync(u,B,O)local F=T:GetGroupsAsync(B)for T=1,#F,1 do local B=F[T]if B.Id==O then return B.Rank end end return 0 end function T.GetRoleInGroupAsync(u,B,O)local F=T:GetGroupsAsync(B)for T=1,#F,1 do local B=F[T]if B.Id==O then return B.Role end end return"\071\117\101\115\116"end function T.GetPrimaryGroupAsync(O,B)local u=T:GetGroupsAsync(B)for T=1,#u,1 do local B=u[T]if B.IsPrimary then return B end end return nil end function T.IsInGroupAsync(u,B,O)local F=T:GetGroupsAsync(B)for T=1,#F,1 do if F[T].Id==O then return true end end return false end function T.IsPrimaryGroupAsync(O,B)local u=T:GetGroupsAsync(B)for T=1,#u,1 do if u[T].IsPrimary then return true end end return false end function T.IsGroupAlly(u,B,O)local F=T:GetGroupAlliesAsync(B)for T=1,#F,1 do if F[T].Id==O then return true end end return false end function T.IsGroupEnemy(u,B,O)local F=T:GetGroupEnemiesAsync(B)for T=1,#F,1 do if F[T].Id==O then return true end end return false end function T.GetGroupAlliesAsync(u,T)local F,L=pcall(B.GetAlliesAsync,B,T)local h=F and(L and O(L))return h end function T.GetEnemiesAsync(u,T)local F,L=pcall(B.GetEnemiesAsync,B,T)local h=F and(L and O(L))return h end function T.GetGroupsAsync(O,T)local u,F=pcall(B.GetGroupsAsync,B,T.UserId)return u and F or{}end function T.GetGroupInfoAsync(O,T)local u,F=pcall(B.GetGroupInfoAsync,B,T)return u and F or{}end return T

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
