UserHasBadgeAsync infinite yield?

To begin, I want to find a way to make my code not yield forever.

So the problem is whenever I try to use “:UserHasBadgeAsync()” it yields infinitely rather than erroring or responding. The weirdest part is it only happens with 1 specific badge.

Normal Badge Output

Broken Badge Output

Here’s my code sample:


local badgeOwned = cacheOwnedBadges[player.UserId][badge]
		
if badgeOwned == nil then
	local worked, data = pcall(function()
		badgeOwned = game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, badge)
	end)
end

Any help solving this issue would be greatly appreciated!

1 Like

badgeOwned stores the value at the current time. Changing it later on in the script does not change the value in the table. The correct code would be

local badgeOwned = cacheOwnedBadges[player.UserId][badge]
		
if badgeOwned == nil then
	local worked, data = pcall(function()
		cacheOwnedBadges[player.UserId][badge] = game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, badge)
	end)
end

Mine does have a cache, you are overlooking the ACTUAL issue. The code sample I used was only the necessary elements. The cache is updated later in the script.

REMEMBER

The actual issue is that “:UserHasBadgeAsync()” is yielding without timing out, erroring, or returning.

Can you add print statements before and after UserHasBadgeAsync

I thought the already attached image made it obvious, but here you go.

That’s very strange then.

Could you provide more of the code because I don’t think the infinite yield is in the exact snippet you added.

Also, I see that in the pcall you did local worked, data, if you’re using data later on in the script, you should return badgeOwner in the pcall

The local worked, data was used earlier in testing to find the issue and isn’t actually a part of the script. The yield is in the snippet I added. Its yielding on the line UserHasBadgeAsync is used but only when I use THIS (657163782152408) badge id.

Figured it out… so closing this.
Just created a new badge and it worked.

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