I need to check if a player has a badge, whilst hundreds of other badges are being checked. (yes, hundreds.)

I am trying to update my game with an event, but this isn’t going as well as I planned. I know how to award the badge, but not check for it in this massive spam of warnings.

Code:

wait(0.1) d = false local BaseText = script.Parent.Text game["Run Service"].Heartbeat:Connect(function() if d == false then d = true if game.BadgeService:UserHasBadgeAsync(script.Parent.Parent.Parent.Parent.Parent.Parent.UserId, 300622221016883) == false then script.Parent.Text = BaseText .. " (Requires badge: Unexpected Pumpkin, Rejoin when got)" script.Parent.BackgroundTransparency = 0.5 script.Parent.TextTransparency = 0.5 script.Parent.Interactable = false else script.Parent.Text = BaseText script.Parent.BackgroundTransparency = 0 script.Parent.TextTransparency = 0 script.Parent.Interactable = true end d = false end end)

No matter what you’re doing, running a web call in Heartbeat is scary and bad practice, you will run into rate limits that way. RunService doesn’t belong here.

On a separate note, BadgeService now has CheckUserBadgesAsync which can check ownership of up to 10 badges per call. If you really need to check for so many badges at one go, you should be using this function instead of UserHasBadgeAsync which only checks against a single badge.

You have an architecturing problem here with little information to go off of. You shouldn’t need to be checking so many badges so often.

2 Likes

the problem is, i have like 50 scripts that use this already. make a plugin which converts all of these, or no.

Which is what I mean by you have an architecturing problem. You should not be using any of BadgeService’s functions that often and across so many scripts.

I have no idea what you mean by “convert”, but if you mean to use the new function, that’s not going to solve your problem. Your entire problem is that you’re using code like this at all.

Again, your thread has very little information to go off of, however it’s clear that you need to do deep refactoring on whatever it is you’re doing so that scripts aren’t checking for so many badges so frequently. As in, most of this should be done in Luau code instead. To me, it sounds like you should only ever be checking badge ownership once and then handling ownership for the rest of the current session without referring back to BadgeService.

2 Likes