This is a fade in and out script for a gui object, in this case it's an ImageLabel.
fade = script.Parent --The ImageLabel
fadeGoal = 0 -- What the transparency should end at. This is 0 so it is fading in.
fadeRate = 0.05 -- How fast it should fade
function updateFade()
local current = fade.ImageTransparency --The background
if current < fadeGoal then --If the current transparency is smaller that the the goal
fade.ImageTransparency = math.min(fadeGoal,current+fadeRate) -- If true add the current transparency from the fade rate
elseif current > fadeGoal then
fade.ImageTransparency = math.max(fadeGoal,current-fadeRate) --If true subtract the current transparency from the fade rate
else
fade.ImageTransparency = fadeGoal -- if the transparency is equel to or bigger than goal sets transparency to goal
end
end
rs = game:GetService("RunService")
fade.Changed:Connect(function()
repeat
fadeGoal = 1
until
script.Parent.ImageTransparency == 1
wait()
repeat
fadeGoal = 0
until
script.Parent.ImageTransparency == 0
wait()
end)
rs.RenderStepped:connect(updateFade)
