Check if player has all existing badges in the game

How do I check if the player has every single badge in the game? There’s 89 badges in my game.
I could just put all of the badge ids in a list and check if the player has every single badge in that list. But the problem is that it’s very slow and inefficient, and checking for too many badges gives an error, and it’s just overall a bad method.

Any thoughts on how to achieve this?

1 Like

Save each badge they earn in a datastore, inside an array. To find how many badges they own(even if they deleted them from their inventory) just add the # operator in front of the array to get the length:

local owned_badges = {0001, 0002, 0003} --array with owned badge ids
local amount = #owned_badges 
local hasAll = (amount == 89) 
print(amount, hasAll)

--to add badge:
table.insert(owned_badges, badge_id)
--to remove badge:
table.remove(owned_badges, table.find(badge_id)) 

The issue with the above method is that it wont apply to players that have already earned the badges.

2 Likes