PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

TextTransparency

TextLabel

float

The TextColor3 property determines the transparency of all the text rendered by a UI element. This property along with TextLabel/Font, TextLabel/TextSize and TextLabel/TextColor3 will determine the visual properties of text. Text is rendered after the text stroke (TextLabel/TextStrokeTransparency).

Fading text in using a numeric for-loop is a fantastic way to draw a player’s attention to text appearing on screen.

-- Count backwards from 1 to 0, decrementing by 0.1
for i = 1, 0, -.1 do
   textLabel.TextTransparency = i
   wait(.1)
end

Code Samples


"Kaboom!" Text

This code sample repeatedly tweens a TextLabel’s TextSize from 5 to 100 and fades out the text as it grows in size.

local textLabel = script.Parent

textLabel.Text = "Kaboom!"

while true do
	for size = 5, 100, 5 do
		textLabel.TextSize = size
		textLabel.TextTransparency = size / 100
		wait()
	end
	wait(1)
end

Fading Banner

This code sample creates a fading banner for a TextLabel. It fades text out, chooses a random string (avoiding repetition), and fades back in.

local textLabel = script.Parent

local content = {
	"Welcome to my game!";
	"Be sure to have fun!";
	"Please give suggestions!";
	"Be nice to other players!";
	"Don't grief other players!";
	"Check out the shop!";
	"Tip: Don't die!";
}

local function fadeOut()
	for i = textLabel.TextTransparency, 1, .1 do
		wait(.1)
		textLabel.TextTransparency = i
	end
end

local function fadeIn()
	for i = textLabel.TextTransparency, 0, -.1 do
		wait(.1)
		textLabel.TextTransparency = i
	end
end

local lastIndex
while true do
	-- Step 0: Fade out before doing anything 
	fadeOut()
	
	-- Step 1: pick content that wasn't the last displayed
	local index	
	repeat
		index = math.random(1, #content)
	until lastIndex ~= index
	-- Make sure we don't show the same thing next time
	lastIndex = index
	
	-- Step 2: show the content
	textLabel.Text = content[index]
	fadeIn()
	wait(2)
end