How would you do it so if you scrolled your cursor, over a GUI button it fades from the color you have it to green, or whatever you choose the color to be?
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.
local mouse = game.Players.LocalPlayer:GetMouse() local myGui = script.Parent local debounce = false local mouseOver = false local colorFrom = Color3.new(0, 255, 0) -- Green (change to myGui.BackgroundColor3 for current color) local colorTo = Color3.new(255, 0, 0) -- Red function gradience(n, color1, color2) --a simple function that returns a color after gradience from color1 to color2 at a specific point *n* of grading. or something like that.. terminology is probably a bit off. local color = {0, 0, 0} color1 = {color1.r, color1.g, color1.b} color2 = {color2.r, color2.g, color2.b} for i = 1, 3 do color[i] = (color1[i] + n * (color2[i] - color1[i]))/255 end return Color3.new(color[1], color[2], color[3]) end function startTransition(i, t, start, finish) --function that changes the BackgroundColor3 of the GUI. **i** represents the amount of iterations from start to finish (value between 0 and 1) and **t** is the delay between each iteration. the smaller t is, the less choppy the transition is. if mouseOver and not debounce then debounce = true for n = start or 0, finish or 1, i or 0.1 do myGui.BackgroundColor3 = gradience(n, colorFrom, colorTo) wait(t or 0) end debounce = false end end myGui.MouseEnter:connect(function() mouseOver = true myGui.MouseLeave:wait() mouseOver = false end) mouse.WheelForward:connect(function() startTransition(0.01) --if **t** isn't given, the wait time between each transition is automatically as fast as it gets (0 or 0.03) end) mouse.WheelBackward:connect(function() startTransition(0.01) end)
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.