Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to convert integer value to a string?

I have an integer value, and I need to convert the numbers it displays into a string to show it on a GUI. Any idea how?

[EDIT] My script

while true do
	script.Parent.Text = game.Workspace.Shields.Value + "%"
	wait(0.1)
end

2 answers

✓ Accepted answer

If I'm correct, you'd use the tostring method to convert a number or integer to a string.

while true do
    script.Parent.Text = tostring(game.Workspace.Shields.Value .. "%") -- use tostring method to convert integer to string
    wait(0.1)
end

By the way, to combine 2 strings/integers, use .. instead of +, because + makes the script try to add 2 values. You can't add a string + a number.

You can do this one of two ways.

  • Calling the function tostring on the number

    x = tostring(number) print(x)

  • Concatenation

    x = 5 print("High"..x) --> "High5"

7 comments

0

Could you show me how to do that with the script I edited into my question?

0

Why are you adding a symbol to a numerical value?

0

I'm trying to add that on to the string.

0

Like a concatenation.

0

..then use concatenation.. as I did in the second example. (script.Parent.Text = "string"..number)

0

The '+' is used for concatenation in other languages, like JavaScript. Probably confused him.

0

Possible, although I did have an example along with the term.

This discussion is preserved as it was. New answers, comments, and votes are closed.