Hello! Im attempting to use UI gradient, and change the Offset value in a loop (like, with tweenservice) so that the gradient fades through the ImageLabel. (This is for an icon hovering over an NPC’s head.)
Image: Icon - Album on Imgur
My plan was to use TweenService to make it look like a smooth transition.
My issue is I have no experience with this, and my script is a mess and doesnt work. I have no idea how to make something like this work. I was trying to make it cycle through different offsets using a script, however it seems to not work
If anyone knows how I could go about fixing this or making this work let me know, tysm
Maybe theres a more efficient way to go about this, that im not aware of
I just ran into a similar question mere minutes ago. So basically, UIGradients’ properties can’t be tweened natively so you have to create a number value, then tween the number value’s Value property instead (I’m making the assumption that you’re trying to tween the transparency, if you’re trying to tween the colour let me know and I’ll help with that instead)
The effect i was going for was something like out of some mobile games, where you have a UI effect of a bar passing through the button, in a loop.
Like this: fade - Album on Imgur
Yeah you can slow it down with the first argument of the TweenInfo, however adding a delay is a bit harder because we have to wrap it in a loop:
local tweenService = game:GetService('TweenService')
local numberValue = Instance.new('NumberValue')
local uiGradient = script.Parent.UIGradient
numberValue.Changed:Connect(function()
local colorSequenceKeypoints = {
ColorSequenceKeypoint.new(0, Color3.new(1,1,1));
ColorSequenceKeypoint.new(math.clamp(numberValue.Value, 0.001, 0.999), Color3.new());
ColorSequenceKeypoint.new(1,Color3.new(1,1,1))
}
uiGradient.Color = ColorSequence.new(colorSequenceKeypoints)
end)
local tweenInfo = TweenInfo.new(0.5) -- change this to make it slower
while true do
for i = 0,1 do
print('ok')
local tween = tweenService:Create(numberValue, tweenInfo, {['Value'] = i})
tween:Play()
tween.Completed:Wait()
task.wait(1)
end
end