How can i do this? i am new to coding and so dont know much i am still learning i have a hard time with badges in code i want it so when you open the achivements menu it shows as 0.5 transparency if you dont own the badge 0 transparency if you do i will include screenshots below i am also hoping for a script that i can edit easy if you cant do that then its fine
You can use the UserHasBadgeAsync() function provided by the BadgeService, and this will return back a bool (True/False) value if they have the badge or not
This is a yielding function as well, so calling it will pause the Script & prevent its lines of codes from advancing any further until a result has been provided from the function
But since you have more than 1 badge to check, we’ll have to use a table which will hold all of our current Badges that we want to check
-- Put a LocalScript inside your Gui here
local Plr = game.Players.LocalPlayer
local BS = game:GetService("BadgeService")
local Gui = script.Parent
local Badges = {
BadgeName1 = 0000000000, -- Placeholder ID, the comma in this (,) separates each thing inside the table
BadgeName2 = 0000000001,
}
local function CheckBadge(BadgeID)
local BadgeOwned = BS:UserHasBadgeAsync(Plr.UserId, BadgeID)
return BadgeOwned
end
for BadgeName, BadgeID in pairs(Badges) do
local Check = CheckBadge(BadgeID)
local FrameCheck = Gui:FindFirstDescendant(BadgeName)
print("Badge Owned:", Check)
print("Frame in Gui:", FrameCheck)
if FrameCheck then -- Checking if the Frame Name exists in your Gui
if Check == true then -- Checking if the Badge the player owns is true, if so we can change the Frame Transparency!
FrameCheck.BackgroundTransparency = 0
FrameCheck.ImageTransparency = 0 -- Not sure if you want the image transparent as well
else
FrameCheck.BackgroundTransparency = 0.5
FrameCheck.ImageTransparency = 0.5 -- Not sure if you want the image transparent as well
end
end
end
And don’t hesitate to add prints as well, cause that’s essential for script debugging & figuring out what’s wrong inside your code
Print what BadgeOwned gives you inside the CheckBadge function, also make sure to check out what Check & FrameCheck prints back as a result so that there is a proper frame name there
local BS = game:GetService("BadgeService")
local PS = game:GetService("Players")
local player = PS.LocalPlayer
local function SetBadgeTransparency(imageLabel: ImageLabel, badgeId: number)
imageLabel.ImageTransparency = if BS:UserHasBadgeAsync(player.UserId, badgeId) then 0 else .5
end