Hello everyone, I’ve been trying to achieve a falling down text effect recently to implement into my dialogue system.
Here’s a reference of what I want to make :
And this is what I made (it doesn’t work at all)
Heres the code for it :
local TextService = game:GetService("TextService")
local TweenService = game:GetService("TweenService")
local UI = script.Parent
local Frame = UI.TextFrame
local TextDefault = script:WaitForChild("Letter")
local X, Y = 0, 0
local TotalX = 0
local LastLetter : TextLabel = nil
local function TypeLetter(Letter : string)
if TotalX >= Frame.AbsoluteSize.X then Y += 1 TotalX = 0 X = 0 LastLetter = nil end
local Clone = TextDefault:Clone()
Clone.Text = Letter
local Position
if LastLetter ~= nil then
Position = UDim2.new(0, LastLetter.Position.X.Offset + TextService:GetTextSize(Letter, 28, Clone.Font, Clone.AbsoluteSize).X, Y * Clone.Size.Y.Scale)
else
Position = UDim2.new(0, 0, Y * Clone.Size.Y.Scale)
end
Clone.Position = Position - UDim2.fromScale(0, 0.05)
Clone.Name = Letter
Clone.Parent = Frame
TweenService:Create(Clone, TweenInfo.new(.15, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {
Position = Position,
TextColor3 = Color3.fromRGB(139, 139, 139)
}):Play()
X += 1
TotalX = Position.X.Offset
LastLetter = Clone
end
game.ReplicatedStorage.Event.Event:Connect(function(Sentence : string)
for i = 1, #Sentence do
TypeLetter(string.sub(Sentence, i, i))
task.wait(.05)
end
end)
The issue is that you’re not factoring size into the letter position! If you set the AnchorPoint of Letter to 0.5, 0 – this code will work:
local TextService = game:GetService("TextService")
local TweenService = game:GetService("TweenService")
local UI = script.Parent
local Frame = UI.TextFrame
local TextDefault = script:WaitForChild("Letter")
local X, Y = 0, 0
local TotalX = 0
local LastLetter : TextLabel = nil
local function TypeLetter(Letter : string)
if TotalX >= Frame.AbsoluteSize.X then Y += 1 TotalX = 0 X = 0 LastLetter = nil end
local Clone = TextDefault:Clone()
Clone.Text = Letter
Clone.Parent = Frame
local letterSize = TextService:GetTextSize(Letter, 28, Clone.Font, Clone.AbsoluteSize)
Clone.Size = UDim2.new(0, letterSize.X, Clone.Size.Y.Scale, 0)
local Position
if LastLetter ~= nil then
local lastLetterPos = LastLetter.Position.X.Offset + (LastLetter.Size.X.Offset / 2)
Position = UDim2.new(0, lastLetterPos + (letterSize.X / 2), Y * Clone.Size.Y.Scale)
else
Position = UDim2.new(0, letterSize.X / 2, Y * Clone.Size.Y.Scale)
end
Clone.Position = Position - UDim2.fromScale(0, 0.05)
Clone.Name = Letter
TweenService:Create(Clone, TweenInfo.new(.15, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {
Position = Position,
TextColor3 = Color3.fromRGB(139, 139, 139)
}):Play()
X += 1
TotalX = Position.X.Offset + (Clone.Size.X.Offset / 2)
LastLetter = Clone
end
game.ReplicatedStorage.Event.Event:Connect(function(Sentence : string)
for i = 1, #Sentence do
TypeLetter(string.sub(Sentence, i, i))
task.wait(.05)
end
end)
With this, I am just adding letterSize.X/2 to the last letter position
Hope this pushes you in the right direction! Good luck!