Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't the background transparency change?

Asked by 9 years ago

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,

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

0
The only thing is, is that 'b' will be the same value throughout since it's only evaluated once at the start DigitalVeer 1473 — 9y
1
Yes, that's precisely what would be wanted. It ranges between (b) transparency and completely invisible. There's no reason for that to change throughout the script since you would want it to be the same. BlueTaslem 18071 — 9y
0
What I had assumed is that he wanted it loop the Transparency from what the current Transparency is, not a constant value DigitalVeer 1473 — 9y
Ad

Answer this question