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?
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.
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
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
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.