Badge Progression Tracking
The BadgeTracker wraps Roblox’s BadgeService to prevent common award errors, track completion rates, and measure how long it takes players to earn specific badges.
Events Dispatched
Section titled “Events Dispatched”| Event Name | Category | Description |
|---|---|---|
BadgeAwardSuccess |
badge |
Emitted when a badge is successfully awarded to a user. |
BadgeAwardFailed |
badge |
Emitted when the award attempt fails (e.g. rate limit or API failure). |
BadgeAlreadyOwned |
badge |
Emitted when the user already possesses the badge, skipping the award call. |
Safe Awarding Method
Section titled “Safe Awarding Method”Use Analytics:AwardBadge instead of raw BadgeService:AwardBadge:
local BADGE_ID = 212456789
local ok, wasAwarded, err = Analytics:AwardBadge(player, BADGE_ID)
if wasAwarded then print("Player earned a new badge!")elseif not ok then warn("Badge award failed with error:", err)endWhy use Analytics:AwardBadge?
Section titled “Why use Analytics:AwardBadge?”- Pre-checks Ownership: Calls
BadgeService:UserHasBadgeAsyncfirst, saving rate limits and avoiding redundant calls. - Measures Time-to-Earn: Automatically logs
timeToEarnSeconds(time elapsed since player joined the server). - Safe pcall Wrapper: Prevents unhandled Roblox API exceptions from crashing your scripts.
Manual Recording
Section titled “Manual Recording”If your game already has its own badge award framework, you can hook telemetry into it without changing your logic:
Analytics:RecordBadgeAward(player.UserId, BADGE_ID, true, nil)Querying Badge Statistics
Section titled “Querying Badge Statistics”-- Total times a specific badge has been awarded on this serverlocal count = Analytics:GetBadgeAwardCount(BADGE_ID)
-- Total badges of all types awarded on this serverlocal total = Analytics:GetTotalBadgesAwarded()