Hello!
I currently have a script which iterates through each badge and checks if the player owns it, however I have run into the problem where it creates a lot of requests, and I plan on adding quite a few more badges which I fear might cause errors. It currently works as expected but I think switching methodology might be a good idea as well.
So I’m brought to a dilemma, should I:
a) create a badge table inside of the player’s data to show what badges were awarded, or
b) keep going how I’m going right now
So here’s what my badge checker looks like right now, and keep in mind that I have around 10 badges right now:
local function checkBadges(player)
local leaderstats = player:WaitForChild('leaderstats')
local stage = leaderstats:WaitForChild('Stage')
local data = playerData:WaitForChild(player.UserId)
if stage.Value >= 10 then
local success, userOwnsBadge = pcall(badgeService.UserHasBadge, badgeService, player.UserId, 2124801810)
if success and not userOwnsBadge then
pcall(badgeService.AwardBadge, badgeService, player.UserId, 2124801810)
end
end
for i,v in pairs(difficultyHandler) do
if type(v) == 'table' and v.Stages.Max + 1 <= stage.Value then
local success, userOwnsBadge = pcall(badgeService.UserHasBadge, badgeService, player.UserId, v.Badge)
if success and not userOwnsBadge then
pcall(badgeService.AwardBadge, badgeService, player.UserId, v.Badge)
elseif not success then
warn('Couldn\'t get badge status because',userOwnsBadge)
end
end
end
local inventory = data:WaitForChild('Inventory')
for i,v in pairs(badges) do
if inventory:FindFirstChild(i) then
local success, userOwnsBadge = pcall(badgeService.UserHasBadge, badgeService, player.UserId, v)
if success and not userOwnsBadge then
pcall(badgeService.AwardBadge, badgeService, player.UserId, v)
end
end
end
end
Thanks for any insight!