Typewriter GUI stopping at letter one

Hello. I am working on a typewriter effect. The script is not working. If anyone knows how to fix please tell me.

local TextLabel =  script.Parent
local Text

function SoundEffect()
	local Sound = Instance.new("Sound",workspace)
	Sound.Name = "TextSound"
	Sound.SoundID = "https://www.roblox.com/asset/?id=4724430129"
	Sound.PlaybackSpeed = 1
	Sound.Volume = 2
	Sound:Play()
	coroutine.resume(coroutine.create(function()
		wait(1)
		Sound:Destroy()
	end))
end

function setText(word)
	Text = word
	for i = 1, #Text do
		TextLabel.Text = string.sub(Text, 1, i)
		SoundEffect()
		TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
		wait(0.05) --reminder for carrot, text speed dont lose it.
	end
end
wait(3)
setText("Hey...")
wait(2)
setText("Oh, its a player.")
wait(3)
setText("Welcome to the game! Its a little lonely in here and we're waiting for you to join in on the fun!")
wait(5)
setText("Make sure you dislike the game first before, we don't want any likers to join in the party...")
wait(4.5)
setText("This game is about being disliked, and nothing else, nothing to see here except for dislikes.")
wait(4.5)
Images

e
w

Honestly, your best answer is simply to read this article, and use its typewriter module. It is easily customizationable, and I’ve used it in several of my games. Super easy to use
Roblox’s Typewriter

best of luck, hope this helps! It should be what you need

Well, hello. The code seems good itself. But few things have to be fixed and few are on your own mind.

• [MAIN MAIN MAIN] - Wrong syntax

function setText(word)
  Text = word
  for i = 1, string.len(Text) do
......

LUA has library called “string”. This library lets the developer to do such operations like find text in text, cut the text or count the text lengh. You had to use string.len(text_to_get_lengh) here because of you tried to make a table count in text. #table is only for couning elements in tables, not in text or number.

• Put the sound somewhere near the script. - on your own opinion
You don’t need a sound to be placed in workspace if it’s in PlayerGui or any of its descendants. It would be 2D sound, but still hearable. So, you can place sound once, not over and over. Also, roblox might (not sure) to try to load this sound over and over

• Change script to LocalScript - on your own opinion
This won’t help the code work better, but it would make code run on the device. If this code is being runned on server, if player has high ping - this might to get such delays like “He” → “Hey…” because of not enough time to replicate all of information.

PS. Hell, it finally appeared

I created my own module for typewriting a few weeks or so ago. Instead of using string.sub, I just concatenated the old string with the new string:

local stringToTypeWrite = 'Hello'
stringToTypeWrite = string.split(stringToTypeWrite, '')
local finalString = ''
TextLabel.TextColor3 = Color3.fromRGB(255,255,255) -- Another thing, you only have to set the textlabel's text once
for i,letter in pairs(stringToTypeWrite) do
    TextLabel.Text = finalString..letter
    wait(0.05)
end

I ran code and watched what error do you get. It’s the code that works. There were only 2 mistakes, so, there was no need to change the function algoritm to fix the code.

local TextLabel = script.Parent
local Text

function SoundEffect()
    local Sound = Instance.new("Sound",workspace)
    Sound.Name = "TextSound"
    Sound.SoundId = "https://www.roblox.com/asset/?id=4724430129"
    Sound.PlaybackSpeed = 1
    Sound.Volume = 2
    Sound:Play()
    coroutine.resume(coroutine.create(function()
        wait(1)
        Sound:Destroy()
    end))
end

function setText(word)
    Text = word
    for i = 1, string.len(Text) do
        TextLabel.Text = string.sub(Text, 1, i)
        SoundEffect()
        wait(0.05) --reminder for carrot, text speed dont lose it.
    end
end

wait(3)
setText("Hey...")
wait(2)
setText("Oh, its a player.")
wait(3)
setText("Welcome to the game! Its a little lonely in here and we're waiting for you to join in on the fun!")
wait(5)
setText("Make sure you dislike the game first before, we don't want any likers to join in the party...")
wait(4.5)
setText("This game is about being disliked, and nothing else, nothing to see here except for dislikes.")
wait(4.5)
1 Like