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
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
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"
This discussion is preserved as it was. New answers, comments, and votes are closed.
7 comments
Could you show me how to do that with the script I edited into my question?
Why are you adding a symbol to a numerical value?
I'm trying to add that on to the string.
Like a concatenation.
..then use concatenation.. as I did in the second example. (script.Parent.Text = "string"..number)
The '+' is used for concatenation in other languages, like JavaScript. Probably confused him.
Possible, although I did have an example along with the term.