Skip to content

Instantly share code, notes, and snippets.

@mvyasu
Created November 19, 2022 08:53
Show Gist options
  • Select an option

  • Save mvyasu/3fcc53c2700060f634a97fcd5fa168a6 to your computer and use it in GitHub Desktop.

Select an option

Save mvyasu/3fcc53c2700060f634a97fcd5fa168a6 to your computer and use it in GitHub Desktop.
A simple typewriter example that allows for the previously set text to be overwritten without any problems.
local textLabel = script.Parent
local lastUpdateTextThread = nil
local function updateText(newText: string)
if lastUpdateTextThread then
task.cancel(lastUpdateTextThread)
lastUpdateTextThread = nil
end
lastUpdateTextThread = task.spawn(function()
textLabel.MaxVisibleGraphemes = 0
textLabel.Text = newText
local totalGraphemes = utf8.len(newText)
for i = 1,totalGraphemes do
textLabel.MaxVisibleGraphemes = i
task.wait(1/100)
end
textLabel.MaxVisibleGraphemes = -1
end)
end
local function onCurrentTextChanged()
updateText(textLabel:GetAttribute("CurrentText"))
end
textLabel:GetAttributeChangedSignal("CurrentText"):Connect(onCurrentTextChanged)
onCurrentTextChanged()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment