Scripting Fading GUI

How would I make this script so that it fades in when you touch the part, but it fades out after the 3.5 seconds?

Popup = script.Parent.ScreenGui
Ready = true
function onTouch(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h ~= nil and Ready == true then
		Ready = false
		local plyr = game.Players:FindFirstChild(h.Parent.Name) 
		local c = Popup:clone()
		c.Parent = plyr.PlayerGui
		wait(3.5)
		c:remove()
		wait(1)
		Ready = true
	end
end

script.Parent.Touched:connect(onTouch)

.

You can use TweenService!

TweenService is used for interpolating properties smoothly, which you can read more about here.

To use it, you need 3 things.

  1. The instance you want to change
  2. A TweenInfo object
  3. A table of properties

Here’s an example of across a part after 3.5 seconds:

local Info = TweenInfo.new(3.5) -- First argument is seconds, others are optional
local Table = {Transparency = 1}
local Part = workspace.Part
local TweenService = game:GetService("TweenService")

local tween = TweenService:Create(Part,Info,Table)
tween:Play()
tween.Completed:Wait() -- waits until the tween has finished