Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't the background transparency change?

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

✓ Accepted answer

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.

3 comments

0

The only thing is, is that 'b' will be the same value throughout since it's only evaluated once at the start

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.

0

What I had assumed is that he wanted it loop the Transparency from what the current Transparency is, not a constant value

This discussion is preserved as it was. New answers, comments, and votes are closed.