Tonumber and tostring

Learn how to use "tonumber()" and "tostring()".

by KyleDominicus

Author Avatar


The function "tostring" is used to convert a numbervalue to a stringvalue.

For example:

local value = workspace.NumberValue.Value
local part = workspace.Part

part.Name = tostring(value)

Let's say that the variable "value" is identifying a NumberValue in the

workspace, and the variiable "part" is finding a "Part" in the workspace.

The "tostring()" will allow me to change the value of the numbervalue to a

stringvalue for naming my part.


The function "tonumber" is very similar to the "tostring()" function.

Tonumber performs the same function, except, it can change a string value

to a number value.

For example:

local text = workspace.StringValue.Value
local numberValue = workspace.NumberValue.Value

numberValue = tonumber(text)

Let's say that the variable "text" is finding a stringvalue under the workspace,

and the variable "numberValue" is finding a NumberValue under the workspace.

With the "tonumber()" function, I can convert the string value for the variable

"text" to a number value.

Hopefully this will help you a little bit while learning LUA.

View in-game to comment, award, and more!