Tostring problems, how to use it?

Hello, I would like to know if someone could provide me with a hand, I need to know how to use tostring what it does and in which use cases to use it, any ideas?
I would appreciate it very much

number = 5
new_number = tostring(number)

print("the number is: "..number)
print("The new number is: "..new_number)

number_to_number = tonumber(new_number)
print("To number is: "..tostring(number_to_number))
7 Likes

tostring basically justs converts something into a string,

print(type(1)) --number
print(type(tostring(1))) -- string

In your example you’ve provided, it should do as you want, name the instance to 5 and then later set the number variable to be the name of the Instance as a number. Keep in mind is that if the instance’s name is not a full number, such as if there’s a letter in it, it will set nil into number

You really only need to use tostring if you need to ensure a given value is a string

5 Likes

Is it possible to do this also with a table? :open_mouth:

1 Like

i dont think so
–trythoughorelseyouwontfindout

1 Like

If you tostring a table, it’ll return the memory address the table is located at

image

Which is probably not what you want

1 Like

Thank you guys so much! helped me a lot with my learning! :smiley:

1 Like