Grow a garden affecting other games and script to prevent badgeService from breaking

So… Grow a graden has just reached 16 million players making it the most played game, ever

Congrats to gag for reaching such milestones every other week but this does come with problems and a problem i’ve just been alerted of is the BadgeService going down for a few minutes.

If you are like me and scripted your game expecting the BadgeService to NOT go down then you probably also have seen your game just stop working.

So to prevent this from happening I’ve thrown together a quick module that should stop my game from breaking with the BadgeService.

It’s just a simple pcall but i do have hopes that this works

local Badge = {}
local Service = game:GetService("BadgeService")

function Badge.CheckIfUserHasBadge(UserID, BadgeID)
	local Status
	
	local Success, Error = pcall(function()
		Status = Service:UserHasBadgeAsync(UserID, BadgeID)
	end)
	
	return Status
end

return Badge

If anyone has anaything to add to this please just say

5 Likes

This works for your purpose but you should also make it so it tries again if it fails.

Something like:

local function hasBadge()
    local Status
    local Success, Error = pcall(function()
		Status = Service:UserHasBadgeAsync(UserID, BadgeID)
	end)
    return Status, success
end
function Badge.CheckIfUserHasBadge(UserID, BadgeID)
	local Status, success
	local count = 0
	while true do
       Status, success = hasBadge()
       count += 1
       if (Status and success == true) or count > 4 then break end -- don't overdo it
       task.wait(0.1)
    end
	
	return Status
end

BadgeService shouldn’t just go down randomly, sometimes it can fail so it’s good practice to try again.

4 Likes

This is pretty much how it operates outside the module but i think i should write this as a solution for others

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.