Solved How to make gui transparency go to 0 when you own the badge 0.5 when you dont

in screen gui
image

1 Like

Try this out:

local BS = game:GetService("BadgeService")
local PS = game:GetService("Players")

local player = PS.LocalPlayer
local gui = script.Parent

local function SetBadgeTransparency(imageLabel: ImageLabel, badgeId: number)
	imageLabel.ImageTransparency = if BS:UserHasBadgeAsync(player.UserId, badgeId) then 0 else .5
end

SetBadgeTransparency(gui.Achivementsopen, 0) -- replace 0 with your badge id

that as the whole script or in one part of it?

1 Like

and since it adresses one do i put the script in each achivement?

1 Like

Using BadgeService and whether the user has that badge. They have an API for it or whatever its called.

Try out whole script.


Clone this line

SetBadgeTransparency(gui.Achivementsopen, 0) -- replace 0 with your badge id

and replace the first parameter with your preferred gui object, and the second parameter for the badge ID.

so do i replace Achivementopen with my gui i want to be transparency 0.5 and 0

1 Like

Pretty much, yeah.

[dont mind this]

sorry i keep asking things but can you explain how it turns it from 0.5 to 0 if you own it and 0 to 0.5 if you dont? (the image transparency)

1 Like

never mind i figured it out by my self how it works

It works but it only works when you rejoin is there a way you can make it different?

local BS = game:GetService("BadgeService")
local PS = game:GetService("Players")

local player = PS.LocalPlayer
local gui = script.Parent

local function SetBadgeTransparency(imageLabel: ImageLabel, badgeId: number)
	imageLabel.ImageTransparency = if BS:UserHasBadgeAsync(player.UserId, badgeId) then 0 else .5
end

SetBadgeTransparency(gui.Frame.MetOwner, 2128256385)
SetBadgeTransparency(gui.Frame.Played, 2128256380)
1 Like

What do you mean by that?

[dont mind this]

when you rejoin it refreshes the transparency not automaticly

you have to rejoin for it to work

1 Like

Have you tried playing it in-game (i.e. not in Roblox Studio)?

yes public game test game

{dumb text amount}

1 Like

Replace the function with this, and check the console:

local function SetBadgeTransparency(imageLabel: ImageLabel, badgeId: number)
	local success, hasBadge = pcall(function()
		return BS:UserHasBadgeAsync(player.UserId, badgeId)
	end)
	
	if success then
		warn("successfully ran! status: " .. hasBadge)
		imageLabel.ImageTransparency = if hasBadge then 0 else .5
	else
		warn("something failed!")
	end
end

you have to rejoin for it to update if you own the badge the code works just i want it to run always (update always) rather than having to rejoin

1 Like

And it gives a unknown variable thing in the code for SetBadgeTransparency

Have you checked console?

[dont mind this]