Help with uigradient

i want to tween my uigradient’s transparency , the grad is transparent , i want to make it tween transparency from left to center and from right to center at same time ,

but transparency cant be tweened on uigrads

how to tween this bro

local ts=game:GetService('TweenService')
game:GetService('UserInputService').InputBegan:Connect(function(input)
	if input.UserInputType==Enum.UserInputType.MouseButton3 then
		grad=script.Parent.UIGradient
		local keys=grad.Transparency.Keypoints
		Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0, 0), NumberSequenceKeypoint.new(0.5, 0),NumberSequenceKeypoint.new(.6,0), NumberSequenceKeypoint.new(1, 0)}
			grad.Transparency=Transparency
	end
end)

local repeatcount = -1
local starttime = tick()
local reversedirection = false

while repeatcount == -1 or repeatcount > 0 do
	local elapsedtime = tick() - starttime
	local alpha = elapsedtime / 2

	if alpha >= 1 then
		reversedirection = not reversedirection
		starttime = tick()
		if repeatcount > 0 then
			repeatcount -= 1
		end
	end

	local progress = math.clamp(alpha % 1, 0, 1)
	if reversedirection then
		progress = 1 - progress
	end

	script.Parent:WaitForChild("UIGradient").Transparency = NumberSequence.new{
		NumberSequenceKeypoint.new(0, 0),
		NumberSequenceKeypoint.new(0.5, progress),
		NumberSequenceKeypoint.new(1, 0)
	}

	game:GetService("RunService").RenderStepped:Wait()
end

can you make this one work ?

local ts=game:GetService('TweenService')
game:GetService('UserInputService').InputBegan:Connect(function(input)
	if input.UserInputType==Enum.UserInputType.MouseButton3 then
		grad=script.Parent.UIGradient
		local keys=grad.Transparency.Keypoints
		val1=Instance.new('NumberValue');val1.Value=0
		val2=Instance.new('NumberValue');val2.Value=1
		local function func()
			grad.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0, 0), NumberSequenceKeypoint.new(val1.Value, 0),NumberSequenceKeypoint.new(val2.Value,0), NumberSequenceKeypoint.new(1, 0)}
		end
		val1:GetPropertyChangedSignal'Value':Connect(func)
		val2:GetPropertyChangedSignal'Value':Connect(func)
		ts:Create(val1,TweenInfo.new(2),{Value=.5}):Play()
		ts:Create(val2,TweenInfo.new(2),{Value=.6}):Play()
	end
end)

bro i meant this ,


why using math.clamp and os.clock , i solved my problem , i didnt know that i can add a table of keypoints as an arg in numbersequence function and you helped me knowing this .

bro its same but its in loop you and why are you using number value even can use variable for that and its also optimized way to do that

Its not the same , mine goes from right to center + left to center . The one you gave was also good but only makes a bar goes to right and goes to left and repeat again that wasn’t what i wanted because it is really easy to do this with 1 single NumberValue , but still thanks for information .

Also i want to tween number value , because i cant tween a variable, also i don’t want to use RunService to increase variable , since the number is between 0 and 1 , it is better to use NumberValue to be able to tween it by TweenService, it’s much more smoother .