I tried to make a imageLabel script, that on begining his ImageTransparency is on 1 but when waited 2 seconds its value is lowered down 0.25 every 0.001 second by the function that will be disabled in 1 sec after function enable, but when waited 5 seconds after function disabled, it will run another function that will raise up its value by 0.25 every 0.001 second.
but it only showing up expect hiding. Here is a script:
local function decreaseTransparency()
while true do
wait(0.001)
script.Parent.ImageLabel.ImageTransparency = script.Parent.ImageLabel.ImageTransparency - 0.25
end
end
local function increaseTransparency()
while true do
wait(0.001)
script.Parent.ImageLabel.ImageTransparency = script.Parent.ImageLabel.ImageTransparency + 0.50
end
end
wait(2)
decreaseTransparency(true)
wait(1)
decreaseTransparency(false)
wait(5)
increaseTransparency(true)
wait(1)
increaseTransparency(false)
You are not using the parameters that you pass with the decreaseTransparency() or increaseTransparency().
while true do
wait(0.001)
script.Parent.ImageLabel.ImageTransparency = script.Parent.ImageLabel.ImageTransparency - 0.25
end
This snippet will run no matter what as soon as you call that function because you are not using the parameter that you pass with the function, but just use the true bool value which is the value that while ... do ... end loops need to run.
Instead, you can merge both increase and decrease functions into one and use repeat ... until ...:
local function EnableTransparency(value) -- Aceept parameters here so we can use them.
if value then
-- If the passed value is true:
repeat
script.Parent.ImageLabel.ImageTransparency += 0.50 -- += 0.50 is the same as "ImageTransparency = ImageTransparency + 0.50", but shorter.
task.wait(0.001)
until script.Parent.ImageLabel.ImageTransparency == 1 -- Until the Image is transparent.
else
-- If the passed value is not true:
repeat
script.Parent.ImageLabel.ImageTransparency -= 0.25 -- -= 0.25 is the same as "ImageTransparency = ImageTransparency - 0.25", but shorter.
task.wait(0.001)
until script.Parent.ImageLabel.ImageTransparency == 0 -- Until the Image is non-transparent.
end
end
EnableTransparency(true) -- Makes the Image transparent.
EnableTransparency(false) -- Makes the Image non-transparent.
Notes:
Never use wait, but use task.wait() since wait() is deprecated and task.wait() is more accurate.
Preferably, you can use TweenService for your case because ImageTransparency can’t be higher than 1 or lower than 0.