Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

0

You are using quite a lot of while loops. Consider creating a function instead.

1 answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.