CONTEXT: I have a mute icon. If the player's mouse enters the mute icon, a line of text should fade into view above the mute icon, and when the player's mouse leaves the mute icon, the line of text should fade out of view.
THE PROBLEM: The text is not fading in or out correctly. It's transparency stays at 14/15 when the mouse enters and doesn't get any lower. It needs to get to 13/15, 12/15, and so on until it reaches 0/15. Instead, the mouse enters and the transparency is 15/15 - 1/15. Then when the mouse leaves the transparency is 14/15 + 1/15.
RELEVANT CODE:
local mute = Instance.new("ImageButton")
mute.Name = "mute"
mute.Parent = screenGui
mute.Image = "http://www.roblox.com/asset/?id=154834667"
mute.ZIndex = 2
mute.BackgroundTransparency = 1
mute.Size = UDim2.new(0.025,0,0.0625625,0)
mute.Position = UDim2.new(0.005,0,0.9335,0)
local mutetext = Instance.new("TextLabel",screenGui)
mutetext.Name = "mutetext"
mutetext.Position = UDim2.new(0.005,0,0.91,0)
mutetext.BackgroundTransparency = 1
mutetext.TextXAlignment = "Left"
mutetext.Text = "Scroll/click to adjust music volume"
mutetext.TextWrapped = false
mutetext.TextTransparency = 1
mutetext.TextStrokeTransparency = 1
mutetext.TextScaled = false
mutetext.Visible = true
mutetext.Font = "Arial"
mutetext.FontSize = Enum.FontSize.Size14
mutetext.Active = true
mute.MouseEnter:connect(function()
inText = true -- Variable set to true to detect when the mouse has entered the mute icon
end)
mute.MouseLeave:connect(function()
inText = false -- Variable set to false to detect when the mouse has left the mute icon
end)
transparencyConstant = 1/15 -- The increment in which the text should fade in or out
function fadeIn() -- Function used to fade the text in
MTtransparency = mutetext.TextTransparency
MTtransparency = MTtransparency - transparencyConstant -- Supposed to make less transparent (fade in) by subtracting 1/15 every wait()
MTtransparency = math.max(0, MTtransparency) -- The transparency of mute text cannot be lower than 0
print(MTtransparency) -- Used for debugging purposes
end
function fadeOut()
local MTtransparency = mutetext.TextTransparency
print(MTtransparency)
MTtransparency = MTtransparency + transparencyConstant -- Supposed to make more transparent by adding 1/15 every wait()
MTtransparency = math.min(1, MTtransparency) -- The transparency of mute text cannot be more than 1
print(MTtransparency) -- Used for debugging purposes
end
local fadeInandOut = coroutine.wrap(function() -- Coroutine so that other code after it can work; other code can run simultaneously
while wait() do -- Checks every wait()
if inText == true then -- If the mouse is in the mute icon, inText is true. And if inText is true, then
fadeIn() -- (cont.) fade the mute text in.
elseif inText == false then -- If the mouse isn't in the mute icon, inText is false. And if inText is false, then
fadeOut() -- (cont.) fade the mute text out.
end
end
end)
fadeInandOut() -- Calls the function
ADDITIONAL DETAILS: The text transparency is apparently 0.9333 when the mouse enters the mute icon. This is 1 - 1/15 -- and 1/15 is my transparencyConstant increment thingy. Also, 0.93333 is printed every wait(). This means that every time inText is true, it's doing 1-1/15. Instead, I want it to do, 1 - 1/15. 14/15 - 1/15. 13/15 - 1/15. All the way to 0, where it must stop due to the line that uses math.max. Here's a picture of what's going on: http://i.imgur.com/PHGH7ap.png
The text transparency is 1 when the mouse leaves the mute icon. This is intended and not a problem: (http://i.imgur.com/AtC0rnz.png)[http://i.imgur.com/AtC0rnz.png]
If you have any questions or concerns, I'd be happy to answer them! If you are able to answer my question sufficiently, you're the best! :)

1 comment
Thanks for the help! So I guess dav1000999 was partially right... I'll give him an upvote