I’m trying to fade a frame in and then out after the transparency reaches 0. I’ve got the fading in part down, but the transparency does not stop and increase when it hits 0, but instead starts going into the negatives.
How do I fix this and add transparency when the frame hits 0 transparency?
Script:
local MainFrame = script.Parent
local LoadingGui = script.Parent.Parent
while wait(0.01) do
if MainFrame.BackgroundTransparency <= 1 then
MainFrame.BackgroundTransparency -= 0.01
if MainFrame.BackgroundTransparency == 0 then do
MainFrame.BackgroundTransparency += 0.01
end
end
end
local MainFrame = script.Parent
local LoadingGui = script.Parent.Parent
while wait(0.01) do
if MainFrame.BackgroundTransparency <= 1 then
MainFrame.BackgroundTransparency -= 0.01
if MainFrame.BackgroundTransparency == 0 then do
MainFrame.BackgroundTransparency += 0.01
break until
MainFrame.BackgroundTransparency <= 1
MainFrame.BackgroundTransparency -= 0.01
end
end
end
TweenInfo.new(1 --[[specific time it takes to tween]], Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 123 --[[the amount of times you want it to repeat]], true --[[whether it reverses or not, set to true for what you want to do.]])
local Tween = tweenService:Create(MainFrame, TweenInfo.new(1 --[[specific time it takes to tween]], Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 123 --[[the amount of times you want it to repeat]], true --[[whether it reverses or not, set to true for what you want to do.]])) --[[time your tween takes]], {BackgroundTransparency = 1})
Tween:Play()
You don’t need any of this, just replace it with this:
local tweenService = game:GetService('TweenService')
local Tween = tweenService:Create(MainFrame, TweenInfo.new(1 --[[specific time it takes to tween]], Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 123 --[[the amount of times you want it to repeat]], true --[[whether it reverses or not, set to true for what you want to do.]])) --[[time your tween takes]], {BackgroundTransparency = 1})
Tween:Play()