UserHasBadgeAsync failed due to empty response

So I got a server script, it gives you a tool when you got a specific badge, the error is:

need to fix

And the script is:

local BadgeService = game:GetService("BadgeService")
local Tool = game:GetService("ServerStorage"):WaitForChild("Chocolate Milk")
local BadgeId = 1111111111

game.Players.PlayerAdded:Connect(function(player)
	if BadgeService:UserHasBadgeAsync(player.UserId,BadgeId) then
		Tool:Clone().Parent = player.Backpack
		Tool:Clone().Parent = player.StarterGear
	end
end)

I don’t see any issues with the current code. You should change the badge id to an actual badge id so it doesn’t check for something that doesn’t exist (probably the issue you’re seeing).

local BadgeService = game:GetService("BadgeService")
local Tool = game:GetService("ServerStorage"):WaitForChild("Chocolate Milk")
local BadgeId = 1111111111

game.Players.PlayerAdded:Connect(function(player)
	if BadgeService:UserHasBadgeAsync(player.UserId,BadgeId) then
		local ClonedTool = Tool:Clone()
		CloneTool.Parent = player.Backpack
	end
end)

The real badge code is not like that anyway, I wrote it that way when I was sharing it.

The item given in the clone event goes from the inventory after the character respawns and that’s not the main issue, the main issue is UserHasBadgeAsync error

I copied your given script put it in studio, replaced the BadgeId with a badge I own - it worked.

Other similar issues have been talking about this, too, suggesting this is a Roblox issue: UserHasBadgeAsync failed due to empty response.

It already works at first, it starts to give this error after a while as the person increases

I think it is necessary to write the code with pcall, but I did not understand how to write it, I could not

Just at least so it doesn’t break the whole script when encountering this error:

local BadgeService = game:GetService("BadgeService")
local Tool = game:GetService("ServerStorage"):WaitForChild("Chocolate Milk")
local BadgeId = 0

game.Players.PlayerAdded:Connect(function(player)
	pcall(function()
		if BadgeService:UserHasBadgeAsync(player.UserId,BadgeId) then
			Tool:Clone().Parent = player.Backpack
			Tool:Clone().Parent = player.StarterGear
		end
	end)
end)

Just wrap the network call inside pcall the cloning should go outside.

local BadgeService = game:GetService("BadgeService")
local Tool = game:GetService("ServerStorage"):WaitForChild("Chocolate Milk")
local BadgeId = 0

game.Players.PlayerAdded:Connect(function(player)
	local res, err = pcall(function() return BadgeService:UserHasBadgeAsync(player.UserId,BadgeId) end)
	if not res then warn(err) return end --Output error if one occurred.
	Tool:Clone().Parent = player.Backpack --May need 'WaitForChild'.
	Tool:Clone().Parent = player.StarterGear --May also need 'WaitForChild'.
end)

I don’t see a mistake, but it gives that item to everyone in the game, even if they don’t have badge

if not err then return end

Add this line before the cloning occurs.

Use a pcall and retry, this is a roblox issue
All type of web requests should be done with safe calls because there can be network issues, unlike server services functions and methods

Still same problem, “it gives that item to everyone in the game, even if they don’t have badge”

I’ve edited the previous reply.

Also since you have a RBXScriptConnection (aka a false thread) erroring won’t break the entire script but rather the current thread

Of course nobody likes errors, but it’s not a critical issue there

1 Like