Hi, I’m a novice developer developing a storygame. This is supposed to be a typewriter effect alone but how can I improve this? (if there’s something that could be improved on)
game.ReplicatedStorage.SendText.OnClientEvent:Connect(function(text)
script.Parent.Visible = true
for i = 1, #text do
script.Parent.Ticker.Text = string.sub(text, 1, i)
wait(0.04) --This is the speed of the text
end
end)
game.ReplicatedStorage.Countdown.OnClientEvent:Connect(function()
for i = 5, 0, -1 do
script.Parent.Parent.TextLabel.Text = tostring(i)
end
script.Parent.Parent.TextLabel.Text = ""
end)
I might add a clicking sound that plays each time a letter is added. Just make sure that you create the sound before the loop so you’re not creating a new instance every single time a letter is added.
There’s a much easier way! You can control how long it takes and even the easingstyle of the characters appearing like this, using MaxVisibleGraphemes.
Here’s how I’d make it for your case:
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
4, -- it takes 4 seconds for the effect to complete
Enum.EasingStyle.Sine, -- typing starts fast and slows near the end
Enum.EasingDirection.Out
)
game.ReplicatedStorage.SendText.OnClientEvent:Connect(function(text)
script.Parent.Visible = true
script.Parent.Text = text
script.Parent.MaxVisibleGraphemes = 0
local tween = TweenService:Create(script.Parent, tweenInfo, {
-- Final value should be the total grapheme count
MaxVisibleGraphemes = utf8.len(textObject.ContentText),
})
tween:Play()
end)
It’s up to you if you prefer to use this, I personally think it allows for easier control for special FX and stuff.