You can use loops and basic addition/subtraction to simplify this or the way I did it (@blub20074 suggested it ) which is tweening it, it is really smooth.
local part = script.Parent
local TS = game:GetService("TweenService")
local TweenInformation
function OnTouch()
TweenInformation = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
local goal = {}
goal.Transparency = 1
local tween1 = TS:Create(part, TweenInformation, goal)
tween1:Play()
part.CanCollide = false
wait(5)
TweenInformation = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local goal = {}
goal.Transparency = 0
local tween2 = TS:Create(part, TweenInformation, goal)
tween2:Play()
part.CanCollide = true
end
part.Touched:Connect(OnTouch)