Use the BadgeService: https://developer.roblox.com/en-us/api-reference/class/BadgeService
You could create a table of badges that your game owns:
Then iterate through the table with pairs/ipairs and use :UserHasBadgeAsync (link: https://developer.roblox.com/en-us/api-reference/function/BadgeService/UserHasBadgeAsync) then for each badge the player owns, count up by 1.
1 | local badgeService = game:GetService( "BadgeService" ) |
3 | local badgesOwnedCount = 0 |
4 | for index, badgeID in ipairs (badgeIDs) do |
5 | if badgeService:UserHasBadgeAsync(player.UserId, badgeId) then |
Then where you see the if statement, under it, you just add one to the badgesOwnedCount for each badge the player owns like so:
3 | badgesOwnedCount = badgesOwnedCount + 1 |