Badge Icons on ImageLabels

Hello,

I’m recently working on a Owned Badge GUI which shows all the badges you own from my game. I have one thing that i really want to know how to do but i don’t know how or if it’s possible.

So basically i have ImageLabel and i want them to be the icon of the badge. Is there a way i could get the ImageLabel to show the badge’s icon without reuploading the icons on the Roblox page?

Thanks in advance for the help! :smiley:

1 Like

You have BadgeService. I do not think theres other way than creating an object with all badges ids, loop though it and do BadgeService:GetBadgeInfoAsync(ID). It returns image iirc.

EDIT: BadgeService:GetBadgeInfoAsync you have IconImageId

Could you if you would write that in a script since I’m not the best at scripting :grimacing:

When you get GetBadgeInfoId, do .IconImageId .

BadgeService:GetBadgeInfoId(Id).IconImageId --image id

Developer forum is not place to ask for ready code, but i can give you some example…

local badges = {123456789} -- it contains ids of all badges
local BadgeService = game:GetService("BadgeService")

for i, v in pairs(badges) do
   -- You need to check if user has badge here too, or what ever you want to do
   print(BadgeService:GetBadgeInfoAsync(v).IconImageId) -- returns image id
end

As i can see, there is no GetBadgeInfoId

Oh, it’s async, thanks for reminding me

Also you should wrap it in pcalls, I also forgot to do that lol

local imageLabel = script.Parent
local badgeService = game:GetService("BadgeService")
local getBadgeInfoAsync = badgeService.GetBadgeInfoAsync

local badgeId = 0 --Change to ID of badge.

local function getBadgeImage(badgeId, maxTries)
	maxTries = maxTries or 5
	if maxTries == 0 then return end
	maxTries -= 1
	
	local success, result = pcall(getBadgeInfoAsync, badgeService, badgeId)
	if success then
		if result then
			return result.IconImageId
		end
	else
		warn(result)
		task.wait()
		getBadgeImage(badgeId, maxTries)
	end
end

local badgeImageId = getBadgeImage(badgeId)
if badgeImageId then
	imageLabel.Image = "rbxassetid://"..badgeImageId
end

Yep, i was about to write it. Just remember to use loop like i did in my code, rest is fine :slight_smile:

Depends if you want to check one or more badges, if you’re working with multiple badges then you’d just need to call the function for each badge ID.

On a side note, you should wrap API calls in pcall() as they are prone to errors, i.e; if the BadgeService is down/the client’s connection disconnects.

Just use for loops, no need to use repeat

There is no repeat until loop in my implementation.

If you’re referring to the maxTries parameter, then that’s present in case the issued request drops/fails allowing the request to be reissued.

its more than one badge, soo…

yea i use it in my code, forgor here :skull:

i really dont get it, its kind of no useful code i think

i really dont get it, its kind of no useful code i think

You may want to take another look at the script to see its purpose.

like, you define it on every function use and you call that func once. Its not making sense. maybe i have bad practises from ts.

Thanks everyone for the help! If that’s ok with yall i will be marking this as the solution of this topic. :smiley: