Ghi chú phát hành
Học
Lớp công cụ
GroupService
Không Thể Tạo
Dịch Vụ
Không Sao Chép

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.


Tóm Tắt
Thành viên kế thừa
Mẫu mã
Kiểm tra Đồng minh/Kẻ thù của Nhóm
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
-- Định nghĩa ID nhóm ở đây
local GROUP_ID = 271454
-- Hàm tiện ích để xử lý các trang
local function pagesToArray(pages)
local array = {}
while true do
for _, v in ipairs(pages:GetCurrentPage()) do
table.insert(array, v)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
return array
end
-- Lấy danh sách các đồng minh và kẻ thù
local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
-- Chuyển đổi sang mảng
local allies = pagesToArray(alliesPages)
local enemies = pagesToArray(enemiesPages)
local function playerAdded(player)
-- Kiểm tra xem người chơi có nằm trong nhóm không
if player:IsInGroupAsync(GROUP_ID) then
print(player.Name .. " là một thành viên!")
else
local isAlly, isEnemy = false, false
-- Kiểm tra xem người chơi có nằm trong bất kỳ nhóm đồng minh nào không
for _, groupInfo in ipairs(allies) do
local groupId = groupInfo.Id
if player:IsInGroupAsync(groupId) then
isAlly = true
break
end
end
-- Kiểm tra xem người chơi có nằm trong bất kỳ nhóm kẻ thù nào không
for _, groupInfo in ipairs(enemies) do
local groupId = groupInfo.Id
if player:IsInGroupAsync(groupId) then
isEnemy = true
break
end
end
if isAlly and not isEnemy then
print(player.Name .. " là một đồng minh!")
elseif isEnemy and not isAlly then
print(player.Name .. " là một kẻ thù!")
elseif isEnemy and isAlly then
print(player.Name .. " vừa là đồng minh vừa là kẻ thù!")
else
print(player.Name .. " không phải là đồng minh cũng không phải là kẻ thù!")
end
end
end
-- Lắng nghe sự kiện người chơi mới được thêm vào
Players.PlayerAdded:Connect(playerAdded)
-- Xử lý các người chơi đã ở trong trò chơi
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end

Tài Liệu Tham Khảo API
Phương Pháp
GetAlliesAsync
Sinh Lợi
Các khả năng: Groups
GroupService:GetAlliesAsync(groupId:number):StandardPages
Tham Số
groupId:number
Lợi Nhuận
Mẫu mã
GroupService:GetAlliesAsync
local Players = game:GetService("Players")
local GroupService = game:GetService("GroupService")
local GROUP_ID = 57
-- tạo một bảng chứa tất cả những đồng minh của một nhóm nhất định
local allies = {}
local pages = GroupService:GetAlliesAsync(GROUP_ID)
while true do
for _, group in pairs(pages:GetCurrentPage()) do
table.insert(allies, group)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
function onPlayerAdded(player)
for _, group in pairs(allies) do
if player:IsInGroupAsync(group.Id) then
print("Người chơi là một đồng minh!")
break
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
-- xử lý người chơi đã gia nhập trong khi danh sách đồng minh vẫn đang tải
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
Kiểm tra Đồng minh/Kẻ thù của Nhóm
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
-- Định nghĩa ID nhóm ở đây
local GROUP_ID = 271454
-- Hàm tiện ích để xử lý các trang
local function pagesToArray(pages)
local array = {}
while true do
for _, v in ipairs(pages:GetCurrentPage()) do
table.insert(array, v)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
return array
end
-- Lấy danh sách các đồng minh và kẻ thù
local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
-- Chuyển đổi sang mảng
local allies = pagesToArray(alliesPages)
local enemies = pagesToArray(enemiesPages)
local function playerAdded(player)
-- Kiểm tra xem người chơi có nằm trong nhóm không
if player:IsInGroupAsync(GROUP_ID) then
print(player.Name .. " là một thành viên!")
else
local isAlly, isEnemy = false, false
-- Kiểm tra xem người chơi có nằm trong bất kỳ nhóm đồng minh nào không
for _, groupInfo in ipairs(allies) do
local groupId = groupInfo.Id
if player:IsInGroupAsync(groupId) then
isAlly = true
break
end
end
-- Kiểm tra xem người chơi có nằm trong bất kỳ nhóm kẻ thù nào không
for _, groupInfo in ipairs(enemies) do
local groupId = groupInfo.Id
if player:IsInGroupAsync(groupId) then
isEnemy = true
break
end
end
if isAlly and not isEnemy then
print(player.Name .. " là một đồng minh!")
elseif isEnemy and not isAlly then
print(player.Name .. " là một kẻ thù!")
elseif isEnemy and isAlly then
print(player.Name .. " vừa là đồng minh vừa là kẻ thù!")
else
print(player.Name .. " không phải là đồng minh cũng không phải là kẻ thù!")
end
end
end
-- Lắng nghe sự kiện người chơi mới được thêm vào
Players.PlayerAdded:Connect(playerAdded)
-- Xử lý các người chơi đã ở trong trò chơi
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end

GetEnemiesAsync
Sinh Lợi
Các khả năng: Groups
GroupService:GetEnemiesAsync(groupId:number):StandardPages
Tham Số
groupId:number
Lợi Nhuận
Mẫu mã
GroupService:GetEnemiesAsync
local Players = game:GetService("Players")
local GroupService = game:GetService("GroupService")
local GROUP_ID = 57
-- tạo một danh sách tất cả kẻ thù của một nhóm nhất định
local enemies = {}
local pages = GroupService:GetEnemiesAsync(GROUP_ID)
while true do
for _, group in pairs(pages:GetCurrentPage()) do
table.insert(enemies, group)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
function onPlayerAdded(player)
for _, enemyGroup in pairs(enemies) do
if player:IsInGroupAsync(enemyGroup.Id) then
print("Người chơi là kẻ thù!")
break
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
-- xử lý người chơi đã tham gia trong khi danh sách kẻ thù vẫn đang tải
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
Kiểm tra Đồng minh/Kẻ thù của Nhóm
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
-- Định nghĩa ID nhóm ở đây
local GROUP_ID = 271454
-- Hàm tiện ích để xử lý các trang
local function pagesToArray(pages)
local array = {}
while true do
for _, v in ipairs(pages:GetCurrentPage()) do
table.insert(array, v)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
return array
end
-- Lấy danh sách các đồng minh và kẻ thù
local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
-- Chuyển đổi sang mảng
local allies = pagesToArray(alliesPages)
local enemies = pagesToArray(enemiesPages)
local function playerAdded(player)
-- Kiểm tra xem người chơi có nằm trong nhóm không
if player:IsInGroupAsync(GROUP_ID) then
print(player.Name .. " là một thành viên!")
else
local isAlly, isEnemy = false, false
-- Kiểm tra xem người chơi có nằm trong bất kỳ nhóm đồng minh nào không
for _, groupInfo in ipairs(allies) do
local groupId = groupInfo.Id
if player:IsInGroupAsync(groupId) then
isAlly = true
break
end
end
-- Kiểm tra xem người chơi có nằm trong bất kỳ nhóm kẻ thù nào không
for _, groupInfo in ipairs(enemies) do
local groupId = groupInfo.Id
if player:IsInGroupAsync(groupId) then
isEnemy = true
break
end
end
if isAlly and not isEnemy then
print(player.Name .. " là một đồng minh!")
elseif isEnemy and not isAlly then
print(player.Name .. " là một kẻ thù!")
elseif isEnemy and isAlly then
print(player.Name .. " vừa là đồng minh vừa là kẻ thù!")
else
print(player.Name .. " không phải là đồng minh cũng không phải là kẻ thù!")
end
end
end
-- Lắng nghe sự kiện người chơi mới được thêm vào
Players.PlayerAdded:Connect(playerAdded)
-- Xử lý các người chơi đã ở trong trò chơi
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end

GetGroupInfoAsync
Sinh Lợi
Các khả năng: Groups
GroupService:GetGroupInfoAsync(groupId:number):Variant
Tham Số
groupId:number
Lợi Nhuận
Variant
Mẫu mã
GroupService:GetGroupInfoAsync
local GroupService = game:GetService("GroupService")
local GROUP_ID = 377251
local group = GroupService:GetGroupInfoAsync(GROUP_ID)
print(group.Name .. " có các vai trò sau:")
for _, role in ipairs(group.Roles) do
print("Hạng " .. role.Rank .. ": " .. role.Name)
end
Tải Biểu Tượng Nhóm
local GroupService = game:GetService("GroupService")
local function getEmblemAsync(groupId)
local groupInfo = GroupService:GetGroupInfoAsync(groupId)
return groupInfo.EmblemUrl
end
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Size = Vector3.new(5, 5, 1)
part.Position = Vector3.new(0, 5, 0)
local decal = Instance.new("Decal")
decal.Parent = part
part.Parent = workspace
decal.ColorMapContent = Content.fromUri(getEmblemAsync(377251))

GetGroupsAsync
Sinh Lợi
Các khả năng: Groups
GroupService:GetGroupsAsync(userId:User):{any}
Tham Số
userId:User
Lợi Nhuận
Mẫu mã
Lấy thông tin về các Nhóm mà Người Dùng là Thành Viên
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
local function playerAdded(player)
-- tải danh sách thông tin về tất cả các nhóm mà người chơi là thành viên
local groups = GroupService:GetGroupsAsync(player.UserId)
for _, groupInfo in pairs(groups) do
for key, value in pairs(groupInfo) do
print(key .. ": " .. tostring(value))
end
print("--")
end
end
Players.PlayerAdded:Connect(playerAdded)
-- duyệt qua các người chơi hiện có
for _, player in pairs(Players:GetPlayers()) do
playerAdded(player)
end

GetRolesInGroupAsync
Sinh Lợi
Các khả năng: Groups
GroupService:GetRolesInGroupAsync(
userId:User, groupId:number
):Variant
Tham Số
userId:User
groupId:number
Lợi Nhuận
Variant

PromptJoinAsync
Sinh Lợi
Các khả năng: Groups
GroupService:PromptJoinAsync(groupId:number):Enum.GroupMembershipStatus
Tham Số
groupId:number
Mẫu mã
Nhắc nhở người chơi tham gia một nhóm
local GroupService = game:GetService("GroupService")
local GROUP_ID = 377251
-- Điều này nên được thực hiện trong một kịch bản chạy trên client
local success, result = pcall(function()
return GroupService:PromptJoinAsync(GROUP_ID)
end)
if success then
if result == Enum.GroupMembershipStatus.Joined then
print("Người chơi đã tham gia nhóm!")
elseif result == Enum.GroupMembershipStatus.JoinRequestPending then
print("Người chơi có một yêu cầu tham gia đang chờ")
elseif result == Enum.GroupMembershipStatus.AlreadyMember then
print("Đã là thành viên")
else
print("Không tham gia hoặc không đủ điều kiện")
end
else
warn("Lời nhắc thất bại:", result)
end

©2026 Roblox Corporation. Roblox, logo Roblox và Powering Imagination là các nhãn hiệu đã đăng ký và chưa đăng ký của chúng tôi tại Hoa Kỳ và các quốc gia khác.