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

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


สรุป
วิธีการ
AwardBadge(userId: User,badgeId: number):boolean
เลิกใช้แล้ว
IsDisabled(badgeId: number):boolean
เลิกใช้แล้ว
IsLegal(badgeId: number):boolean
เลิกใช้แล้ว
UserHasBadge(userId: User,badgeId: number):boolean
เลิกใช้แล้ว
สมาชิกที่ได้รับทอด

เอกสารอ้างอิงเกี่ยวกับ API
วิธีการ
AwardBadge
เลิกใช้แล้ว

AwardBadgeAsync
ผลตอบแทน
ความสามารถ: AssetManagement
BadgeService:AwardBadgeAsync(
userId:User, badgeId:number
พารามิเตอร์
userId:User
badgeId:number
ส่งค่ากลับ
ตัวอย่างโค้ด
การมอบเหรียญ
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BADGE_ID = 0
local function awardBadge(player, badgeId)
-- ดึงข้อมูลเข็มกลัด
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if success then
-- ยืนยันว่าเข็มกลัดสามารถมอบได้
if badgeInfo.IsEnabled then
-- มอบเข็มกลัด
local awarded, errorMessage = pcall(BadgeService.AwardBadgeAsync, BadgeService, player.UserId, badgeId)
if not awarded then
warn("เกิดข้อผิดพลาดขณะมอบเข็มกลัด:", errorMessage)
end
end
else
warn("เกิดข้อผิดพลาดขณะดึงข้อมูลเข็มกลัด: " .. badgeInfo)
end
end
local function onPlayerAdded(player)
awardBadge(player, BADGE_ID)
end
Players.PlayerAdded:Connect(onPlayerAdded)

CheckUserBadgesAsync
ผลตอบแทน
ความสามารถ: AssetManagement
BadgeService:CheckUserBadgesAsync(
userId:User, badgeIds:{any}
พารามิเตอร์
userId:User
badgeIds:{any}
ส่งค่ากลับ
ตัวอย่างโค้ด
ตรวจสอบเหรียญที่ได้รับในกลุ่ม
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeIds = { 0000000000, 1111111111, 2222222222 } -- เปลี่ยนเป็นรายการ ID รางวัลของคุณ
local function onPlayerAdded(player)
-- ตรวจสอบว่าผู้เล่นมีรางวัลใด ๆ หรือไม่
local success, result = pcall(function()
return BadgeService:CheckUserBadgesAsync(player.UserId, badgeIds)
end)
-- หากมีข้อผิดพลาด ให้แสดงคำเตือนและออกจากฟังก์ชัน
if not success then
warn("เกิดข้อผิดพลาดขณะตรวจสอบว่าผู้เล่น", player.Name, "มีรางวัล:", result)
return
end
local ownedBadgeIds = result
if #ownedBadgeIds == 0 then
print(player.Name, "ไม่มีรางวัลใด ๆ")
else
print(player.Name, "มีรางวัลดังต่อไปนี้:", table.concat(ownedBadgeIds, ", "))
end
end
Players.PlayerAdded:Connect(onPlayerAdded)

GetBadgeInfoAsync
ผลตอบแทน
ความสามารถ: AssetManagement
BadgeService:GetBadgeInfoAsync(badgeId:number):Dictionary
พารามิเตอร์
badgeId:number
ส่งค่ากลับ
ตัวอย่างโค้ด
การรับข้อมูลเหรียญ
local BadgeService = game:GetService("BadgeService")
-- ดึงข้อมูลเหรียญ
local success, result = pcall(function()
return BadgeService:GetBadgeInfoAsync(00000000) -- เปลี่ยนหมายเลขนี้เป็น ID เหรียญที่ต้องการ
end)
-- แสดงข้อมูล
if success then
print("เหรียญ:", result.Name)
print("เปิดใช้งาน:", result.IsEnabled)
print("คำอธิบาย:", result.Description)
print("ไอคอน:", "rbxassetid://" .. result.IconImageId)
else
warn("เกิดข้อผิดพลาดระหว่างการดึงข้อมูลเหรียญ:", result)
end

IsDisabled
เลิกใช้แล้ว

IsLegal
เลิกใช้แล้ว

UserHasBadge
เลิกใช้แล้ว

UserHasBadgeAsync
ผลตอบแทน
ความสามารถ: AssetManagement
BadgeService:UserHasBadgeAsync(
userId:User, badgeId:number
พารามิเตอร์
userId:User
badgeId:number
ส่งค่ากลับ
ตัวอย่างโค้ด
ตรวจสอบเหรียญที่ได้รับ
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeId = 00000000 -- เปลี่ยนให้เป็น ID ของเหรียญของคุณ
local function onPlayerAdded(player)
-- ตรวจสอบว่าผู้เล่นมีเหรียญนี้หรือไม่
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
-- หากมีข้อผิดพลาด ให้เตือนและออกจากฟังก์ชัน
if not success then
warn("เกิดข้อผิดพลาดขณะตรวจสอบว่าผู้เล่นมีเหรียญหรือไม่!")
return
end
if hasBadge then
-- จัดการความเป็นเจ้าของเหรียญของผู้เล่นตามที่ต้องการ
print(player.Name, "มีเหรียญ", badgeId)
end
end
-- เชื่อมต่อเหตุการณ์ "PlayerAdded" กับฟังก์ชัน "onPlayerAdded()"
Players.PlayerAdded:Connect(onPlayerAdded)

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