I have a button in a ScreenGui, and I want its BackgroundTransparency to change from its current BackgroundTransparency to .9 when my mouse enters the button, and when it leaves, it returns to its first BackgroundTransparency. Here is what i got:
b = script.Parent.BackgroundTransparency script.Parent.MouseEnter:connect(function() for i = 1,.9,-.25 do game:GetService("RunService").RenderStepped:wait() script.Parent.BackgroundTransparency = i end end) script.Parent.MouseLeave:connect(function() for i = b,1,.25 do game:GetService("RunService").RenderStepped:wait() script.Parent.BackgroundTransparency = i end end)
Nothing in output either,
In a numeric for
loop, Lua won't go past the bound you give.
Since 1 - .25
is less than .9
, that means it won't even bother with that value; thus the loop is effectively only running at i = 1
.
(The same goes for the reverse).
The simplest solution would be to simply make the step of .25
a smaller number. E.g., .015
will make the transition take about .1
seconds. At the rate you have right now, you're trying to make the transition in 6 milliseconds, which you shouldn't expect to visible.
I'm guessing you would want to use b
in both loops, rather than just the second one.