Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to convert integer value to a string?

Asked by
JJ_B 250 Moderation Voter
8 years ago

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

Log in to vote
2
Answered by
Reselim 35
8 years ago

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.

Ad
Log in to vote
2
Answered by
ImageLabel 1541 Moderation Voter
8 years ago

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"

0
Could you show me how to do that with the script I edited into my question? JJ_B 250 — 8y
0
Why are you adding a symbol to a numerical value? ImageLabel 1541 — 8y
0
I'm trying to add that on to the string. JJ_B 250 — 8y
0
Like a concatenation. JJ_B 250 — 8y
View all comments (3 more)
0
..then use concatenation.. as I did in the second example. (script.Parent.Text = "string"..number) ImageLabel 1541 — 8y
0
The '+' is used for concatenation in other languages, like JavaScript. Probably confused him. Perci1 4988 — 8y
0
Possible, although I did have an example along with the term. ImageLabel 1541 — 8y

Answer this question