Problem with textwriting effect

So I’ve made a textwriting effect but have problems to it

First,I want to make the ‘…’ play slower than the other word/letters
Secondly,I want to make sentences seperate with each other like what I did to the script,but it doesn’t work.

Here’s part of my script

local function typewrite (object , text )
		for i = 1,#text,1 do
			object.Text = string.sub (text,1,i)
			wait (0.075)
		end
	end

	typewrite (dialogue,"Oh no where's my cute lil' birdie?...")
	wait(0.2)
	typewrite (dialogue,"Oh hello there!") wait(0.1) ("Can you help me find my lil' bird?") wait(0.2) ("I'll give you this star I've got here to you in return.")
	end
end)

Hello there. I’d like to point out an oopsie in the script, and also provide you with a solution to your problem.

This line will cause an error, as it constantly creates new environments without the functions calling them.

The solution:

You can use a bool value to truncate the text.
local dialogue = script.Parent

local function typewrite (object , text, truncateBool )
	for i = 1,#text,1 do
		object.Text = string.sub (text,1,i)
		wait (0.075)
	end
	
	if truncateBool then
		for rep = 1,3,1 do
			object.Text ..= "."
			wait(.2)
		end
	end
	
end

typewrite (dialogue,"Oh no where's my cute lil' birdie?",true)
wait(0.2)
typewrite (dialogue,"Oh hello there!",false) wait(0.1) typewrite(dialogue,"Can you help me find my lil' bird?",false) wait(0.2) typewrite(dialogue,"I'll give you this star I've got here to you in return.",false)

This will slowly truncate the text if you specify the boolean to do so.

1 Like
local function typewrite (object , text )
		for i = 1,#text,1 do
			object.Text = string.sub (text,1,i)

            if string.sub(text, i, i + 2) == '...' then
                wait(.14) -- replace .14 with the speed you want for "..."
            else
			    wait(.075)
            end
		end
	end

I’m on mobile at the moment so I’m pretty sure this won’t work.

This would always return false, as string.sub(text,i,i) always reads the i indexed element, which is only 1 character. You can fix this by using

 if string.sub(text, i, i) == '.' then 
1 Like

Just realized that, thanks for letting me know.

1 Like

so what i actually want to do is to make the line stop for a while and then a sentence appear next to the previous one instead of starting a new ‘dialogue page’

Edit:Tell me if ur confused cuz I know I’m bad at explaining

Check it out. I did do the same, but in the correct format. You will always have to call the function.

but now it deletes the previous sentence and start a new one but I want it to continue on the same line instead

local dialogue = script.Parent
dialogue.Text = ""
local function typewrite (object , text, truncateBool)
	for i = 1,#text,1 do
		object.Text ..= string.sub (text,1,i)
		wait (0.075)
	end
	
	if truncateBool then
		for rep = 1,3,1 do
			object.Text ..= "."
			wait(.2)
		end
	end
	
end

typewrite (dialogue,"Oh no where's my cute lil' birdie?",true)
wait(0.2)
typewrite (dialogue,"Oh hello there!",false) wait(0.1) typewrite(dialogue,"Can you help me find my lil' bird?",false) wait(0.2) typewrite(dialogue,"I'll give you this star I've got here to you in return.",false)

This will solve it.

Players.Cypacic.PlayerScripts.AJPrompt:52: attempt to concatenate nil with string

Can you show me the rest of the script? the error might be somewhere else.

Player.PlayerGui.MetaverseEvent.Frame.Name.Text = "SuperGamingNooby"

Players.Cypacic.PlayerScripts.AJPrompt:50: attempt to index string with ‘Text’