Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make the background of a gui flash in and out of transparency?

Asked by 6 years ago

I'm trying to make the background of the gui keep transitioning from being visible to being transparent, this is what I have thought of so far.

BetaPassNeededGui = script.Parent
Up = false
BetaPassNeededGui.BackgroundTransparency = 0
while true do
    print("Script Active")
    wait()
    while Up == true do
        print("Mode = ".. Up)
        while BetaPassNeededGui.BackgroundTransparency <= 1 do
            BetaPassNeededGui.BackgroundTransparency = BetaPassNeededGui.BackgroundTransparency + 0.1
            wait(0.1)
            if BetaPassNeededGui.BackgroundTransparency == 1 then
                Up = false
            end
        end
    while Up == false do
        print("Mode = ".. Up)
        while BetaPassNeededGui.BackgroundTransparency >= 0 do
            BetaPassNeededGui.BackgroundTransparency = BetaPassNeededGui.BackgroundTransparency - 0.1
            wait(0.1)
            if BetaPassNeededGui.BackgroundTransparency == 0 then
                Up = true
            end
        end
    end
end
0
You are using quite a lot of while loops. Consider creating a function instead. Zafirua 1348 — 6y

1 answer

Log in to vote
1
Answered by
oreoollie 649 Moderation Voter
6 years ago
Edited 6 years ago

I think that tweening is a much cleaner way to achieve what you want. If you want to change how long it takes for the transparency to change, modify the ChangeTime variable.

local ChangeTime = 1 -- Time in seconds

local twn
local BGui = script.Parent
local t = game:GetService("TweenService")

BGui.Transparency = 0

while BGui.Visible do
    twn = t:Create(BGui, TweenInfo.new(ChangeTime, Enum.EasingStyle.Linear), {Transparency = 1}) twn:Play()
    twn.Completed:Wait()
    twn = t:Create(BGui, TweenInfo.new(ChangeTime, Enum.EasingStyle.Linear), {Transparency = 0}) twn:Play()
    twn.Completed:Wait()
    twn = nil
    wait()
end

If my answer helped you please make sure to mark it as correct!

Ad

Answer this question