Impara
Classe motore
BadgeService
Non costruibile
Assistenza

*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.


Sommario
Metodi
AwardBadge(userId: User,badgeId: number):boolean
Obsoleto
IsDisabled(badgeId: number):boolean
Obsoleto
IsLegal(badgeId: number):boolean
Obsoleto
UserHasBadge(userId: User,badgeId: number):boolean
Obsoleto
Membri ereditati

Riferimento API
Metodi
AwardBadge
Obsoleto

AwardBadgeAsync
Resa
Capacità: AssetManagement
BadgeService:AwardBadgeAsync(
userId:User, badgeId:number
Parametri
userId:User
badgeId:number
Restituzioni
Campioni di codice
Assegnazione di un Distintivo
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BADGE_ID = 0
local function awardBadge(player, badgeId)
-- Recupera informazioni sul badge
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if success then
-- Conferma che il badge può essere assegnato
if badgeInfo.IsEnabled then
-- Assegna il badge
local awarded, errorMessage = pcall(BadgeService.AwardBadgeAsync, BadgeService, player.UserId, badgeId)
if not awarded then
warn("Errore durante l'assegnazione del badge:", errorMessage)
end
end
else
warn("Errore durante il recupero delle informazioni sul badge: " .. badgeInfo)
end
end
local function onPlayerAdded(player)
awardBadge(player, BADGE_ID)
end
Players.PlayerAdded:Connect(onPlayerAdded)

CheckUserBadgesAsync
Resa
Capacità: AssetManagement
BadgeService:CheckUserBadgesAsync(
userId:User, badgeIds:{any}
Parametri
userId:User
badgeIds:{any}
Restituzioni
Campioni di codice
Controllo dei Badges Ricevuti in Batch
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeIds = { 0000000000, 1111111111, 2222222222 } -- Cambia questo con un elenco dei tuoi ID badge
local function onPlayerAdded(player)
-- Controlla se il giocatore ha uno dei badge
local success, result = pcall(function()
return BadgeService:CheckUserBadgesAsync(player.UserId, badgeIds)
end)
-- Se c'è un errore, emetti un avviso ed esci dalla funzione
if not success then
warn("Errore durante il controllo se il giocatore", player.Name, "ha badge:", result)
return
end
local ownedBadgeIds = result
if #ownedBadgeIds == 0 then
print(player.Name, "non ha alcuno dei badge")
else
print(player.Name, "ha i seguenti badge:", table.concat(ownedBadgeIds, ", "))
end
end
Players.PlayerAdded:Connect(onPlayerAdded)

GetBadgeInfoAsync
Resa
Capacità: AssetManagement
BadgeService:GetBadgeInfoAsync(badgeId:number):Dictionary
Parametri
badgeId:number
Restituzioni
Campioni di codice
Ottenere informazioni sul badge
local BadgeService = game:GetService("BadgeService")
-- Recupera le informazioni sul badge
local success, result = pcall(function()
return BadgeService:GetBadgeInfoAsync(00000000) -- Cambia questo con l'ID del badge desiderato
end)
-- Stampa le informazioni
if success then
print("Badge:", result.Name)
print("Abilitato:", result.IsEnabled)
print("Descrizione:", result.Description)
print("Icona:", "rbxassetid://" .. result.IconImageId)
else
warn("Errore durante il recupero delle informazioni sul badge:", result)
end

IsDisabled
Obsoleto

IsLegal
Obsoleto

UserHasBadge
Obsoleto

UserHasBadgeAsync
Resa
Capacità: AssetManagement
BadgeService:UserHasBadgeAsync(
userId:User, badgeId:number
Parametri
userId:User
badgeId:number
Restituzioni
Campioni di codice
Controllo dei Badge Ottenuti
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeId = 00000000 -- Cambia questo con il tuo ID badge
local function onPlayerAdded(player)
-- Controlla se il giocatore ha il badge
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
-- Se c'è un errore, emetti un avviso ed esci dalla funzione
if not success then
warn("Errore durante il controllo se il giocatore ha il badge!")
return
end
if hasBadge then
-- Gestisci la proprietà del badge del giocatore come necessario
print(player.Name, "ha il badge", badgeId)
end
end
-- Collega gli eventi "PlayerAdded" alla funzione "onPlayerAdded()"
Players.PlayerAdded:Connect(onPlayerAdded)

© 2026 Roblox Corporation. Roblox, il logo Roblox e Powering Imagination sono tra i nostri marchi registrati e non registrati negli Stati Uniti. e altri paesi.