Badge Async allways errors

  1. What do you want to achieve? Keep it simple and clear!
    I want to create a function that awards a player any badge when given an id.
  2. What is the issue? Include screenshots / videos if possible!
    I created a badge but when i use its id in the function it wont get its info and just warns “Error while fetching badge info”
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I know the problem is in the first pcall because success is always false.
-- local BadgeService = game:GetService("BadgeService")
local rep = game:GetService("ReplicatedStorage")
local folder = rep:WaitForChild("EventsB")
local event = folder:WaitForChild("BadgeEvent")
local function awardBadge(player,badgeId)
	local success, badgeInfo = pcall(function()
		return BadgeService:GetBadgeInfoAsync(badgeId)
	end)
        print(success, badgeInfo)
	if success then
		if badgeInfo.IsEnabled then
			local awarded, errorMessage = pcall(function()
				BadgeService:AwardBadge(player.UserId, badgeId)
			end)
			if not awarded then
				warn("Error while awarding badge:", errorMessage)
			end
		end
	else
		warn("Error while fetching badge info")
	end
end
event.OnServerEvent:Connect(awardBadge)

might not be related to solving your problem but could you try BadgeService:UserHasBadgeAsync(player,badgeid)
to check wether player has the badge or not instead of getting the badgeinfo?

if not BadgeService:UserHasBadgeAsync(player,badgeid) then -- if the player does not have a certain badge (well idk how to wrap this in a pcall)
--award badge
end

The API only has one parameter. That’s not exactly the answer.

Apparently, the badge ID might have been incorrect. And why is BadgeService commented out?

1 Like

In the actual script the badge service isn’t in comments.
Your right the badge ID was wrong.

1 Like