How would I tween a UIGradient's transparency?

Hi, how could I tween a uigradient’s transparency? from 0 to 1 in 0.35 seconds? I’ve tried this:

local open2 = tweenservice:Create(
		gradient, -- UI object you're tweening, in this case it's Frame
		TweenInfo.new(0.35), -- Amount of seconds
		{Transparency = 1} -- Goal
)

but it just errors.

1 Like

turn the 1 into a NumberSequence | Roblox Creator Documentation

NumberSequences are not tweenable.

The best way (that I can think of) to do this would be to use a NumberValue as a tween and use its Changed event.

local TweenService = game:GetService("TweenService")

local Gradient = script.Parent.UIGradient
local TValue = Instance.new("NumberValue")

TValue.Parent = Gradient
TValue.Value = Gradient.Transparency.Keypoints[1].Value

TValue.Changed:Connect(function(value)
	Gradient.Transparency = NumberSequence.new(value)
end)

local tween = TweenService:Create(
	TValue,
	TweenInfo.new(.35),
	{Value = 1}
)

tween:Play()
1 Like