How can I get a certain letter in a Text Label?

How can I get a certain letter in a Text Label? I want to make a animated Text Label, but to do so I need to get a certain character in the TextLabel. Refer to the following script:

for i, v in pairs(script.Parent:GetChildren()) do
	if v:IsA("TextLabel") then
		local Btext = v.Text
		v.Text = ""
		local Atext = v.Text
		print(Btext)
		print(Atext)
		print(#Btext[4]) -- Where error occurs
		for i = 1, #Btext, 1 do
			v.Text = v.Text .. #Btext[i]
			wait(0.5)
		end
	end
end

The error is “Players.(PlayerName).PlayerGui.ScreenGui.LocalScript:8: attempt to get length of a nil value”. If you can help thanks

1 Like

It is returning nil since you have not added any text when you showed above the blank value v.Text = ""

1 Like

What do you mean? Btext prints out perfectly.

1 Like

What does it return?
30303030303030

Use string.sub() to get the letter by index.
The first argument is the starting index, the second is the finishing index.
Here’s an example:

local text = "Jayde"
print(text:sub(4, 4)) -- Output: "d".
print(text:sub(4, 5)) -- Output: "de".

#Btext is just the length of the string.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.