Text Tween Function Help

I’m trying to make a function to tween a text’s transparency from 1 to 0. The problem is the text is not reacting and still has a transparency of 1.

local TweenService = game:GetService("TweenService")

local function Dialogue(text)
	local tweenInfo = TweenInfo.new(2)	
	local TweenDialogue = TweenService:Create(text, tweenInfo, {TextTransparency = 0})
	TweenDialogue:Play()
end

Dialogue(game.Players.LocalPlayer.PlayerGui.ScreenGui.Dialogue_Screen1.Dialogue.Text1)

image

local TweenService = game:GetService("TweenService")
local player = game:GetService("Players").LocalPlayer
local text1 = player:WaitForChild("PlayerGui"):FindFirstChild("ScreenGui").Dialogue.Screen1.Dialogue.Text1

local function Dialogue(text)
	local tweenInfo = TweenInfo.new(2)	
	local TweenDialogue = TweenService:Create(text, tweenInfo, {TextTransparency = 0})
	TweenDialogue:Play()
end

Dialogue(text1)

Uh, I don’t think you can tween text transparency? Are you trying to make it fade out? If so, you can just use a for loop.
Example:

local dialogue = game.Players.LocalPlayer.PlayerGui.ScreenGui.Dialogue_Screen1.Dialogue.Text1

for i = 1, 100 do
local transparency = i / 100
dialogue.Transparency = i
task.wait(.02) -- Speed of dialogue fading away
end

I forgot whether this was a fade in or fade out, you can change local transparency to this instead if it’s not the correct fade:

local transparency = 1 - i / 100

Edit: Apparently you can tween text transparency. I learned something new.

You can tween TextTransparency.

You should send us any errors related to your code on the output. All I can think of is this line causing some problems, although without much knowledge as to where your code is located, I could be wrong:

Dialogue(game.Players.LocalPlayer.PlayerGui.ScreenGui.Dialogue_Screen1.Dialogue.Text1)

A possible fix to this is:

local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local LocalPlayerUI = Players.LocalPlayer:WaitForChild("PlayerGui")
local DialogueInterface = LocalPlayerUI:WaitForChild("ScreenGui")

local function Dialogue(text)
	local tweenInfo = TweenInfo.new(2)	
	local TweenDialogue = TweenService:Create(text, tweenInfo, {TextTransparency = 0})
	TweenDialogue:Play()
end

Dialogue(DialogueInterface.Dialogue_Screen1.Dialogue.Text1)

Depending on where you placed your LocalScript, the code may have loaded first before the GUI does (especially if the script is under StarterPlayerScripts or ReplicatedFirst). Using WaitForChild(Item) in Player.PlayerGui should help.

1 Like

I have finally found the solution! All you must do is place the local script inside StarterGui

I hope this helps others facing the same problem! :slightly_smiling_face:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.