UI Problem, please help

I’m new to Roblox Studio, and I want to know how to make a fading UI. As I said, I’m new to coding, so my UI knowledge is horrible. Can one of you guys help me out :smile:?

Thanks a lot,
ParkCityUSA

local Re = 100

for i = 1, Re do
wait()
[your UI].BackgroundTransparency = (Re-i)/Re
end

you can use for loops to make nice fade effect

(place it in a gui)

wait(2)
for i = 0, 1, 0.02 do --fade effect
     script.Parent.BackgroundTransparency = i
     wait()
end

wait(1)

for i = 1, 0, -0.02 do -- reverse it
     script.Parent.BackgroundTransparency = i
     wait()
end

Adding on to what @xaoix00 has shown you, right after the wait(1) I would suggest adding this:
script.Parent.BackgroundTransparency = 0
In the past, whenever I’ve used this method, I’ve had issues where it doesn’t go all the way down to 0 and the GUI is still visible. This line makes sure that doesn’t happen.

Ok! I’ll try everyone’s idea and if I have more questions I’ll ask! :+1:

The most reliable method of doing this is Tweening, using TweenService.

Here’s an example and how to use it.

local WhatToChange = BackgroundTransparency -- This is what you want to change 
local ChangeTo = 1 -- This is what you want to change it to
local Object = script.Parent -- The object you want to fade
local Duration = 0.5 -- How long it should play for

	local transitionInfo = TweenInfo.new(Duration, Enum.EasingStyle.Linear)
	local tween = game:GetService("TweenService"):Create(Object, transitionInfo, {WhatToChange = ChangeTo}) 
	tween:Play()

Okay. Do I use a Localscript or just a normal one?

A localscript, I recommend putting the localscript under the thing you want to fade.

The reason you wouldn’t want to use the regular server script (The normal one) is because it will do it for the whole server while we don’t need it to. Localscripts on the other hand will only do this on the one person’s screen.

If I have a TextLabel, will it disappear too?

No, just the thing you put the script under, if you’re looking to do it for a text label and fading the text, put it under the textlabel and change the BackgroundTransparency to TextTransparency.

I don’t recommend loops. I suggest TweenService. Allows for some animating of the effect too!

local TS = game:GetService("TweenService") -- Calls the service
local TI = TweenInfo.new(2) -- Defines a TweenInfo (details about the animation)
-- TweenInfo arguments are as follows: Animation Length, Style, Direction (which 
-- defines when is the 'unique' detail of every animation played, at the start (in), 
-- at the end (out) or both (inout))

local function Fade()
     TS:Create(Object, TI, {BackgroundTransparency = 1}):Play() -- Also a lot to go through with this one
     -- First argument is the object which you change the properties of.
     -- Second argument is the TweenInfo. We defined it earlier.
     -- Third argument is a table, hence the brackets. It defines what properties
     -- we are changing and what the new value of said property is. For now we are
     -- changing the BackgroundTransparency property of an object to 1.
end

Edit: Thanks stranger. Long day.

This is not an exact answer on how to accomplish everything you’re asking, mainly due to the rules of Developer Forum on asking for stuff without showing effort of figuring it out yourself.

You would have to tween both of them, if this is a repetitive task or you have a lot of GUI Objects you should probably make a function that does the Tween for you and accepts a table and does the tween on every GUI Object passed.

local TweenService = game:GetService("TweenService")

local TweenNext = function(Table)
  for _, GuiObject in ipairs(Table) do
    if GuiObject:IsA("GuiObject") then
      TweenService:Create(GuiObject, TweenInfo.new(1), {BackgroundTransparency = 1}):Play()
    end
  end
end

TweenNext({}) -- GuiObjects here

There’s a way more complex way of doing this like making a function that automatically does it to all ancestors and a way of automatically finding out what properties that should be tweened (with pcall).

Helpful links:
Developer - GuiObject
Developer - TweenService

You forgot to actually trigger the Tween by the way.

TweenService:Create(Instance: instance, TweenInfo: tweenInfo, Dictionary: propertyTable):Play()