UserHasBadgeAsync failed due to empty response

So my script is doing this weird thing:


Script:

while wait(10) do
	for i,v in pairs(game.Players:GetChildren()) do
		if v.leaderstats.Stage.Value >= 115 then
			if not game:GetService("BadgeService"):UserHasBadgeAsync(v.UserId,2125468623) then
				game:GetService("BadgeService"):AwardBadge(v.UserId,2125468623)
			end
		end
	end
end

Can anyone fix this?

2 Likes

I’m under the impression that this is probably a general error on Roblox’s side. Async anything has the ability to throw errors like this on occasion. Is this error happening after a certain amount of time? It might be better to simply detect when someone changes stages, instead of doing it every 10 seconds.

An easy way to mitigate this would be wrapping this in a pcall as well.

4 Likes

Right, like basically I just send too many requests because I’m doing a loop every 10 seconds

1 Like

Instead of doing that loop, just put it under a PlayerAdded event, and check when their Stage value is >= 115. + Use a Pcall for the Badge

4 Likes

Yeah, honestly it might be easier to just only fire the loop if they are exactly 115 and then check whenever someones stage value changes (this might be an issue though, as you could end up missing someone on the occasion it errors). Or, add some logic in there that if they are above 115, and they have gotten the badge before, the game wont check for them anymore.

Either way the main thing you’ll want to do is reduce the amount of calls.

1 Like

I’m a beginner, do you mind helping?

instead of doing a while loop to check every 10 seconds, use .changed or getpropertychangedsignal

2 Likes
local badges = game:GetService("BadgeService")
local userHasBadge = badges.UserHasBadgeAsync
local awardBadge = badges.AwardBadge
local badgeId = 2125468623 



game.Players.PlayerAdded:Connect(function(Player)
	Player.leaderstats.Stage.Changed:Connect(function()
		if Player.leaderstats.Stage.Value >= 115 then
			local success,result = pcall(userHasBadge,badges,Player.UserId,badgeId)
			if success then
				if not result then
					badges:AwardBadge(Player.UserId,badgeId)
				end
			end
		end
	end)
end)
4 Likes

I’ll try this, thank you so much

1 Like

You could do in this way aswell:

local badges = game:GetService("BadgeService")
local userHasBadge = badges.UserHasBadgeAsync
local awardBadge = badges.AwardBadge
local badgeId = 2125655691 



game.Players.PlayerAdded:Connect(function(Player)
	Player:WaitForChild("leaderstats").Stage.Changed:Connect(function()
		if Player.leaderstats.Stage.Value >= 115 then
			local success,result = pcall(function()
				return userHasBadge,badges,Player.UserId,badgeId
			end)
			if success then
				--code
			end
		end
	end)
end)
2 Likes


Hmmmm seems somethings wrong with the leaderstat

replace this :

Player.leaderstats.Stage.Changed:Connect(function() with this :

Player:WaitForChild("leaderstats").Stage.Changed:Connect(function()

1 Like

Ohhh right ok yeah I get the error

Also, how can I make the script check even the players has higher stages, because people already started the obby.

The script provided has that implemented already. You can refer to below if needed!

if Player.leaderstats.Stage.Value >= 115 then -- anyone who has a value of 115 or more
if Player.leaderstats.Stage.Value == 115 then -- anyone whos value is exactly 115
if Player.leaderstats.Stage.Value > 115 then -- anyone who is above 115
if Player.leaderstats.Stage.Value <= 115 then -- anyone who is less than or equal to 115
if Player.leaderstats.Stage.Value < 115 then -- anyone who is less than 115

right, but it doesn’t seem to work

Are you testing this in Studio? You’re unable to award badges in studio. If you have a higher stage and you’re testing it on yourself, try it in the actual Roblox game.

I did test it in the actual roblox game

Could you show your current code?

local badges = game:GetService("BadgeService")
local userHasBadge = badges.UserHasBadgeAsync
local awardBadge = badges.AwardBadge
local badgeId = 2125468623 



game.Players.PlayerAdded:Connect(function(Player)
	Player:WaitForChild("leaderstats").Stage.Changed:Connect(function()
		if Player.leaderstats.Stage.Value >= 115 then
			local success,result = pcall(function()
				return userHasBadge,badges,Player.UserId,badgeId
			end)
			if success then
				--code
			end
		end
	end)
end)

ServerScriptService*