Created an advanced TypeWriter Script. (THIS IS CRAZY!)

So I was working on a typewriter script. But instead of giving 1 TextLabel text, and using gsub to add to it, I decided to create a TextLabel for every letter being typed down.

To do this I made a function, and this is what I came up with:

local txts = game:GetService("TextService")
function typeLetter(Letter)
	local TL = script:WaitForChild("Letter"):Clone()
	TL.Text = Letter
	local size = txts:GetTextSize(Letter, TL.TextSize, TL.Font, TL.AbsoluteSize)
	print(size.X)
	XPos = XPos + size.X
	if XPos > 100 then
		YPos = YPos + .4
		XPos = 0
	end
	TL.Position = UDim2.new(XPos, 0, YPos - 0.1, 0)
	TL.Parent = script.Parent:WaitForChild("DescFrame")
	TL:TweenPosition(UDim2.new(XPos,0,YPos,0),"Out", "Quad", .1, true)
	if Letter == "." or Letter == "!" or Letter == "?" then
		wait(.5)
	end
end

It was working for a bit, until I noticed something a little weird going on. The typewriter wasn’t positioning the textlabels the way they should be. Here’s an example of what I mean:
Combat Scripting - Roblox Studio (gyazo.com)

5 Likes

I actually like the error, gives it a creepy vibe. I don’t see a clear way to fix this problem, so you might need to gsub if you don’t like the creepy vibe lol

1 Like

Why use a textlabel for each one? It’s more memory or do you want manual control over the spacing?

@Axospheric The individual textlabels are for the effect of them tweening downwards while iterating through the string and typing them out.

1 Like

@broshv It’s not about the creepy vibe, it’s just the fact that the positioning is off that bugs me. It’s just a little odd how it overlaps other text.

Roblox just made an official typewriter feature recently.

@Elocore Cool! Does it allow me to implement the effect I made on it?

Not sure, I didn’t read much into it, I just thought it might help

Not really to be honest. It’s mostly for the straight typewriter look.

these might be the part that is affecting the positon of the word because its a fixed position you put in lets take M its a bit of a long letter then put I which is a short letter you will position them next to each other within 2 x-axis so the M would clip onto I

Actually the reason for this is because different characters have different spacing and positioning. It might not make sense but i used to have the same problem. To fix this, you have to use a certain function to determine each characters size. Ill reply with it in a bit

1 Like

Should help you. I dont remember how i did it exactly but you need to calculate and add up for each character. This is the hard part.

*edit: Sorry I didn’t read your code. I just skimmed through the comments trying to see what you didn’t accomplish.

Good luck. If you still want help you can reply back

2 Likes