local replicatedstorage = game:GetService("ReplicatedStorage")
local event = replicatedstorage.Event.Fade
local background = script.Parent.Frame.BackgroundTransparency
local db = false
local function unfade()
while task.wait(0.1) do
if background ~= 1 then
script.Parent.Frame.BackgroundTransparency = script.Parent.Frame.BackgroundTransparency +0.1
elseif background == 1 then
script.Parent.Frame.Visible = false
db = false
break
end
end
end
local function fade()
while task.wait(0.1) do
if background ~= 0 then
script.Parent.Frame.BackgroundTransparency = script.Parent.Frame.BackgroundTransparency -0.1
elseif background == 0 then
task.spawn(unfade)
break
end
end
end
event.Event:Connect(function()
if db == false then
db = true
script.Parent.Frame.BackgroundTransparency = 1
script.Parent.Frame.Visible = true
task.spawn(fade)
end
end)
if this is a localscript, use .OnClientEvent instead of .Event
just use tweenservice to reduce the transparency of the frame, then once tween is completed, task.spawn(unfade)
local tService = game:GetService("TweenService")
local tweenParameters = Tweeninfo.new(
1 -- time in seconds, this is how long the tween will take,
Enum.EasingDirection.Out,
Enum.EasingStyle.Linear
)
local fadeTween = tService:Create(InstanceName, tweenParameters, {BackgroundTransparency = 1})
fadeTween:Play() -- call when needed
fadeTween.Completed:Wait() -- will yield until the tween finishes
task.spawn(function)