Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a script that count badges?

So I want to make a script that counts badges but I don't know-how. For example.

print(the number of badges of a player)

1 answer

✓ Accepted answer

Use the BadgeService: https://developer.roblox.com/en-us/api-reference/class/BadgeService

You could create a table of badges that your game owns:

local badgeIDs = {}

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.

local badgeService = game:GetService("BadgeService")

local badgesOwnedCount = 0
for index, badgeID in ipairs(badgeIDs) do
	if badgeService:UserHasBadgeAsync(player.UserId, badgeId) then
		
	end
end

Then where you see the if statement, under it, you just add one to the badgesOwnedCount for each badge the player owns like so:

badgesOwnedCount += 1
-- OR:
badgesOwnedCount = badgesOwnedCount + 1

1 comment

0

alright I'll check it tomorrow but thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.