เรียนรู้
Engine Class
GroupService
ไม่สามารถสร้าง
บริการ
ไม่ซ้ำ

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่


สรุป
สมาชิกที่ได้รับทอด
ตัวอย่างโค้ด
ตัวตรวจสอบกลุ่มพันธมิตร/ศัตรู
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
-- กำหนด ID ของกลุ่มที่นี่
local GROUP_ID = 271454
-- ฟังก์ชันยูทิลิตี้สำหรับจัดการหน้าต่าง
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
-- รับรายการพันธมิตรและศัตรู
local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
-- แปลงเป็นอาร์เรย์
local allies = pagesToArray(alliesPages)
local enemies = pagesToArray(enemiesPages)
local function playerAdded(player)
-- ตรวจสอบว่าผู้เล่นอยู่ในกลุ่มหรือไม่
if player:IsInGroupAsync(GROUP_ID) then
print(player.Name .. " เป็นสมาชิก!")
else
local isAlly, isEnemy = false, false
-- ตรวจสอบว่าผู้เล่นอยู่ในกลุ่มพันธมิตรใด ๆ หรือไม่
for _, groupInfo in ipairs(allies) do
local groupId = groupInfo.Id
if player:IsInGroupAsync(groupId) then
isAlly = true
break
end
end
-- ตรวจสอบว่าผู้เล่นอยู่ในกลุ่มศัตรูใด ๆ หรือไม่
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 .. " เป็นพันธมิตร!")
elseif isEnemy and not isAlly then
print(player.Name .. " เป็นศัตรู!")
elseif isEnemy and isAlly then
print(player.Name .. " เป็นทั้งพันธมิตรและศัตรู!")
else
print(player.Name .. " ไม่เป็นพันธมิตรหรือศัตรู!")
end
end
end
-- ฟังการเพิ่มผู้เล่นใหม่
Players.PlayerAdded:Connect(playerAdded)
-- จัดการผู้เล่นที่อยู่ในเกมแล้ว
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end

เอกสารอ้างอิงเกี่ยวกับ API
วิธีการ
GetAlliesAsync
ผลตอบแทน
ความสามารถ: Groups
GroupService:GetAlliesAsync(groupId:number):StandardPages
พารามิเตอร์
groupId:number
ส่งค่ากลับ
ตัวอย่างโค้ด
GroupService:GetAlliesAsync
local Players = game:GetService("Players")
local GroupService = game:GetService("GroupService")
local GROUP_ID = 57
-- สร้างตารางของพันธมิตรทั้งหมดของกลุ่มที่กำหนด
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("ผู้เล่นเป็นพันธมิตร!")
break
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
-- จัดการผู้เล่นที่เข้าร่วมในขณะที่รายการพันธมิตรยังโหลดอยู่
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
ตัวตรวจสอบกลุ่มพันธมิตร/ศัตรู
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
-- กำหนด ID ของกลุ่มที่นี่
local GROUP_ID = 271454
-- ฟังก์ชันยูทิลิตี้สำหรับจัดการหน้าต่าง
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
-- รับรายการพันธมิตรและศัตรู
local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
-- แปลงเป็นอาร์เรย์
local allies = pagesToArray(alliesPages)
local enemies = pagesToArray(enemiesPages)
local function playerAdded(player)
-- ตรวจสอบว่าผู้เล่นอยู่ในกลุ่มหรือไม่
if player:IsInGroupAsync(GROUP_ID) then
print(player.Name .. " เป็นสมาชิก!")
else
local isAlly, isEnemy = false, false
-- ตรวจสอบว่าผู้เล่นอยู่ในกลุ่มพันธมิตรใด ๆ หรือไม่
for _, groupInfo in ipairs(allies) do
local groupId = groupInfo.Id
if player:IsInGroupAsync(groupId) then
isAlly = true
break
end
end
-- ตรวจสอบว่าผู้เล่นอยู่ในกลุ่มศัตรูใด ๆ หรือไม่
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 .. " เป็นพันธมิตร!")
elseif isEnemy and not isAlly then
print(player.Name .. " เป็นศัตรู!")
elseif isEnemy and isAlly then
print(player.Name .. " เป็นทั้งพันธมิตรและศัตรู!")
else
print(player.Name .. " ไม่เป็นพันธมิตรหรือศัตรู!")
end
end
end
-- ฟังการเพิ่มผู้เล่นใหม่
Players.PlayerAdded:Connect(playerAdded)
-- จัดการผู้เล่นที่อยู่ในเกมแล้ว
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end

GetEnemiesAsync
ผลตอบแทน
ความสามารถ: Groups
GroupService:GetEnemiesAsync(groupId:number):StandardPages
พารามิเตอร์
groupId:number
ส่งค่ากลับ
ตัวอย่างโค้ด
GroupService:GetEnemiesAsync
local Players = game:GetService("Players")
local GroupService = game:GetService("GroupService")
local GROUP_ID = 57
-- สร้างรายการของศัตรูทั้งหมดของกลุ่มที่กำหนด
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("ผู้เล่นเป็นศัตรู!")
break
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
-- จัดการผู้เล่นที่เข้าร่วมในขณะที่รายการศัตร กำลังโหลดอยู่
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
ตัวตรวจสอบกลุ่มพันธมิตร/ศัตรู
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
-- กำหนด ID ของกลุ่มที่นี่
local GROUP_ID = 271454
-- ฟังก์ชันยูทิลิตี้สำหรับจัดการหน้าต่าง
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
-- รับรายการพันธมิตรและศัตรู
local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
-- แปลงเป็นอาร์เรย์
local allies = pagesToArray(alliesPages)
local enemies = pagesToArray(enemiesPages)
local function playerAdded(player)
-- ตรวจสอบว่าผู้เล่นอยู่ในกลุ่มหรือไม่
if player:IsInGroupAsync(GROUP_ID) then
print(player.Name .. " เป็นสมาชิก!")
else
local isAlly, isEnemy = false, false
-- ตรวจสอบว่าผู้เล่นอยู่ในกลุ่มพันธมิตรใด ๆ หรือไม่
for _, groupInfo in ipairs(allies) do
local groupId = groupInfo.Id
if player:IsInGroupAsync(groupId) then
isAlly = true
break
end
end
-- ตรวจสอบว่าผู้เล่นอยู่ในกลุ่มศัตรูใด ๆ หรือไม่
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 .. " เป็นพันธมิตร!")
elseif isEnemy and not isAlly then
print(player.Name .. " เป็นศัตรู!")
elseif isEnemy and isAlly then
print(player.Name .. " เป็นทั้งพันธมิตรและศัตรู!")
else
print(player.Name .. " ไม่เป็นพันธมิตรหรือศัตรู!")
end
end
end
-- ฟังการเพิ่มผู้เล่นใหม่
Players.PlayerAdded:Connect(playerAdded)
-- จัดการผู้เล่นที่อยู่ในเกมแล้ว
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end

GetGroupInfoAsync
ผลตอบแทน
ความสามารถ: Groups
GroupService:GetGroupInfoAsync(groupId:number):Variant
พารามิเตอร์
groupId:number
ส่งค่ากลับ
Variant
ตัวอย่างโค้ด
GroupService:GetGroupInfoAsync
local GroupService = game:GetService("GroupService")
local GROUP_ID = 377251
local group = GroupService:GetGroupInfoAsync(GROUP_ID)
print(group.Name .. " มีบทบาทดังต่อไปนี้:")
for _, role in ipairs(group.Roles) do
print("อันดับ " .. role.Rank .. ": " .. role.Name)
end
โหลดตราสัญลักษณ์กลุ่ม
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
ผลตอบแทน
ความสามารถ: Groups
GroupService:GetGroupsAsync(userId:User):{any}
พารามิเตอร์
userId:User
ส่งค่ากลับ
ตัวอย่างโค้ด
การดึงกลุ่มที่ผู้ใช้เป็นสมาชิก
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
local function playerAdded(player)
-- โหลดรายการข้อมูลเกี่ยวกับกลุ่มทั้งหมดที่ผู้เล่นเป็นสมาชิก
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)
-- ผ่านผู้เล่นที่มีอยู่
for _, player in pairs(Players:GetPlayers()) do
playerAdded(player)
end

GetRolesInGroupAsync
ผลตอบแทน
ความสามารถ: Groups
GroupService:GetRolesInGroupAsync(
userId:User, groupId:number
):Variant
พารามิเตอร์
userId:User
groupId:number
ส่งค่ากลับ
Variant

PromptJoinAsync
ผลตอบแทน
ความสามารถ: Groups
GroupService:PromptJoinAsync(groupId:number):Enum.GroupMembershipStatus
พารามิเตอร์
groupId:number
ส่งค่ากลับ
ตัวอย่างโค้ด
กระตุ้นให้ผู้เล่นเข้าร่วมกลุ่ม
local GroupService = game:GetService("GroupService")
local GROUP_ID = 377251
-- ควรทำการนี้ในสคริปต์ที่รันบนลูกค้า
local success, result = pcall(function()
return GroupService:PromptJoinAsync(GROUP_ID)
end)
if success then
if result == Enum.GroupMembershipStatus.Joined then
print("ผู้เล่นเข้าร่วมกลุ่มแล้ว!")
elseif result == Enum.GroupMembershipStatus.JoinRequestPending then
print("ผู้เล่นมีคำขอเข้าร่วมที่ยังค้างอยู่")
elseif result == Enum.GroupMembershipStatus.AlreadyMember then
print("เป็นสมาชิกอยู่แล้ว")
else
print("ไม่ได้เข้าร่วมหรือไม่ตรงตามคุณสมบัติ")
end
else
warn("การแจ้งเตือนไม่สำเร็จ:", result)
end

©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ