How Can I Improve My Type Write Script?

How Can I Improve My Type Write Script?

local function TypeWrite(object,text,waittime)
	--Object Is Must A TextLabel
	--Text Must Be A String
	--Waittime Must be A Number
	for i = 1,#text,1 do
		object.Text = string.sub(text,1,i)
		wait(waittime)
	end
end

Maybe…

  • Instead of comments, you can place an if statement or an assert to check if the object is really a text label; the same with the “waittime” and “text” parameters
  • Replacing “wait()” with “task.wait()”
1 Like

Instead of using string.sub(), you can use a “for” loop to change the MaxVisibleGraphemes in the text label. You would have to set the TextLabel.Text to the string you desire before running the loop.

2 Likes

You could polish the code by using the newer functions such as task.wait(), and by using better variable casing for easier readability.

local function Typewrite(Object,Text,WaitTime)
	for i = 1,string.len(Text),1 do
		Object.Text = string.sub(Text,1,i)
		task.wait(WaitTime)
	end
end

Besides that, looks fine to me.

4 Likes

Thank You All For Helping :smile:

I would check out the MaxVisibleGraphemes property in most text objects, instead of updating the text each time (it’s more efficient!) Instead of updating the text, you can tween the property to animate how much text is visible!

1 Like