[SOLVED] How to Tween Fade a "ImageLabel" using "ImageTransparency"

Where would I interpret the ImageTransparency in this code so that it will Tween Fade the ImageLabel

-- Tween Control
local function ApplyTweenFade(Frame, Info : TweenInfo, Amount : number)
	local Target= {}
	if (Frame:IsA("GuiObject")) then
		Target.BackgroundTransparency = Amount
	elseif (Frame:IsA("UIStroke")) then
		Target.Transparency = Amount
	else
		return
	end
	TweenService:Create(Frame, Info, Target):Play()
end
1 Like

I’ve added Instance Variables –

-- Gui
local StaminaGui = script.Parent
local Holder = StaminaGui:WaitForChild("Holder")
local Bar = Holder:WaitForChild("Bar")
local Label = Holder:WaitForChild("StaminaLabel")
local UIStroke = Holder:WaitForChild("UIStroke")
local UIStrokeTransparency = UIStroke.Transparency
local BackgroundTransparency = Bar.BackgroundTransparency
local ImageTransparency = Label.ImageTransparency
Holder.Visible = false -- Start hidden
1 Like

So you want to fade the label?

elseif Frame:IsA("ImageLabel") then
    Target.ImageTransparency = 1
end

So it would end up like:
TweenService:Create(Frame, TweenInfo.new(--[[info here]]), {ImageTransparency = 1})

2 Likes

this is the full Tween Fade for (AppyTweenFade) and (TweenFade)

-- Tween Control
local function ApplyTweenFade(Frame, Info : TweenInfo, Amount : number)
	local Target= {}
	if (Frame:IsA("GuiObject")) then
		Target.BackgroundTransparency = Amount
	elseif (Frame:IsA("UIStroke")) then
		Target.Transparency = Amount
	else
		return
	end
	TweenService:Create(Frame, Info, Target):Play()
end

local function TweenFade(Frame, Amount : number)
	local Info = TweenInfo.new (FadeTime)
	ApplyTweenFade(Frame, Info, Amount)
	for k, v in pairs(Frame:GetDescendants()) do
		if (v:IsA("GuiObject")) then
			ApplyTweenFade(Frame, Info, Amount)
		end
	end
end

local function HideStaminaBar()
	TweenFade(Bar, 1)
	TweenFade(UIStroke, 1)
	TweenFade(Holder, 1)
	TweenFade(Label, 1)
	_stambarIsHidden = true
end

local function ShowStaminaBar()
	TweenFade(Bar, 0.8)
	TweenFade(UIStroke, 0.8)
	TweenFade(Holder, 0.5)
	TweenFade(Label, 0.5)
	_stambarIsHidden = false
end
1 Like

You could insert an if statement before the GuiObject class to check if the object is an ImageLabel first.

This is because the ImageLabel object is part of the GuiObject class.

local function ApplyTweenFade(Frame, Info : TweenInfo, Amount : number)
	local Target= {}
	if (Frame:IsA("ImageLabel")) then
		Target.ImageTransparency = Amount
	elseif (Frame:IsA("UIStroke")) then
		Target.Transparency = Amount
	elseif (Frame:IsA("GuiObject")) then
		Target.BackgroundTransparency = Amount
	else
		return
	end
	TweenService:Create(Frame, Info, Target):Play()
end
1 Like

thanks you so much!! It finally works you saved me a lot of time.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.