How would I get the length of a string and then make it display like 12345 (if the length is 5)?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to turn letters into numbers

  2. What is the issue? Include screenshots / videos if possible!
    I dont know how to do it, this is what i want to do: image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked in the developer hub but I didn’t see anything

1 Like
idk if can help you

1 Like

Can you elaborate a bit more?

Do you mean:
Get the length of a string and then make it display like 12345 (if the length is 5)?

1 Like

yes something like that can you tell me how would I do it?

local someString = "Hello world!"
local stringLength = string.len(someString)
local numberSeq = ""
for i = 1, stringLength do
	numberSeq = numberSeq..i
1 Like

I don’t know exactly what this means, but if you want to get a number based on a string, luau has something called “tonumber(string)”, it returns nil if the string cannot be converted to a number, and returns the number in case that the string can be converted to a number, here a code example:

local String = "Hello 1234"

for _, StringElement in pairs(string.split(String, "")) do
	if tonumber(StringElement) ~= nil then
		print(StringElement.." Is a number!")
1 Like

Well, yes…
Here’s an example:

local String = 'Hello'
local Number = ''

for i = 1, (#String) do
	Number = Number .. i

1 Like

wait, you can use this

local str = "" --your string
local length = tonumber(#str)
1 Like

No, that won’t work the way OP wants it to.
You are basically getting the lenght of the string.

1 Like

He wants a string of some length to be converted into a sequence of numbers starting from 1 and ending with the length of the string.

1 Like

I use the “#str” because if I use the conventional method it does not detect several keys (example: {} [] ())
or well, it does not detect them to me

1 Like

I understand now, to achieve this you just need to use “string.split()”, that will return a table with each letter of the string with its respective number, example code:

local String = "Hello"

print(string.split(String, ""))


I hope i helped you to solve the problem, if so, be sure to mark my reply as a solution :slight_smile:

1 Like

Still, you are currently just getting the length of the string, which is not what he wants.

1 Like

You should probably read above as there are currently 2 fully-working codes.
And, this post already has a solution.

thats is the length of the script

the solution was marked as solved just a few seconds ago, and my reply was made before there was a solution, you should pay attention!

Edit: my reply is the solution now :wink:

You should pay attention actually, as people commented way before you did.
Anyways, this comment is off-topic, so is yours.

Let’s just leave it.

1 Like