UserHasBadgeAsync failed due to empty response

hey there, I’ve made a badge gui, and I get an error

the code

local BadgeService = game:GetService("BadgeService")
local BadgeId = 2124909460
local player = game.Players.LocalPlayer
while wait(8) do
	if BadgeService:UserHasBadge(player.UserId, BadgeId) then
		script.Parent.Visible = true
		script.Parent.Parent.cross.Visible = false
	else
		script.Parent.Parent.cross.Visible = true
		script.Parent.Visible = false
	end
end

Try using UserHasBadgeAsync instead. UserHasBadge is deprecated.

3 Likes

On your image, it says that the script is a local script. On the developer hub, it says that it must be called from a server script.

3 Likes

I get the same with “UserHasBadgeAsync”

1 Like

Did you use a script or a localscript?

What does your code look like?

A script
image

Something like this may work

local Players = game:GetService("Players")

local Part = script.Parent
local BadgeId = 0 -- Your badge id here

local UsersToNotGiveBadge = {1115747243} -- Put the user id's that you don't want it to give the bagde to here
Part.Touched:Connect(function(Hit)
	if Players:GetPlayerFromCharacter(Hit.Parent) then
		local Player = Players:GetPlayerFromCharacter(Hit.Parent)
		
		if table.find(UsersToNotGiveBadge, Player.User) then
			return
		end
		
		local Success, HasBadge = pcall(function()
			return BadgeService:UserHasBadgeAsync(Player.UserId, BadgeId)
		end)
		
		if not HasBadge then
			
			task.wait(1)
			local AwardSuccess, Result = pcall(function()
				return BadgeService:AwardBadge(Player.UserId, BadgeId)
			end)
			
		end
	end
end)