By "fading" I assume you mean a "gradient" transition
The WheelForward and WheelBackward events do not fire for GUI, they only fire for the mouse object. However, we can use the mouse and WheelForward/WheelBackward events in conjunction with a GUI to determine whether or not the mouse is hovering over the GUI.
Once we figure out how to get the scroll events to work in conjunction with our GUI we need to figure out how to implement grading. I've already added a generic function that handles grading.
The following code must be in a LocalScript
in order for it to function in online mode.
01 | local mouse = game.Players.LocalPlayer:GetMouse() |
02 | local myGui = script.Parent |
05 | local mouseOver = false |
07 | local colorFrom = Color 3. new( 0 , 255 , 0 ) |
08 | local colorTo = Color 3. new( 255 , 0 , 0 ) |
10 | function gradience(n, color 1 , color 2 ) |
11 | local color = { 0 , 0 , 0 } |
12 | color 1 = { color 1. r, color 1. g, color 1. b } |
13 | color 2 = { color 2. r, color 2. g, color 2. b } |
15 | color [ i ] = (color 1 [ i ] + n * (color 2 [ i ] - color 1 [ i ] ))/ 255 |
17 | return Color 3. new(color [ 1 ] , color [ 2 ] , color [ 3 ] ) |
20 | function startTransition(i, t, start, finish) |
21 | if mouseOver and not debounce then |
23 | for n = start or 0 , finish or 1 , i or 0.1 do |
24 | myGui.BackgroundColor 3 = gradience(n, colorFrom, colorTo) |
31 | myGui.MouseEnter:connect( function () |
33 | myGui.MouseLeave:wait() |
37 | mouse.WheelForward:connect( function () |
41 | mouse.WheelBackward:connect( function () |
Edit: the WheelForward and WheelBackward events don't fire when the mouse is hovering over a TextButton (or ImageButton) so myGUI needs to be a TextLabel, ImageLabel or Frame.