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

How do you output a variable's value into a string?

New to lua, mainly use ruby. In ruby, if i wanted to print a value, say, health, I could do

hp = 100
print "HP: #{hp} /100

and it would output "HP: 100/100"

How does this translate into lua? None of the results I found on google worked in studio.

1 comment

1

print(hp .. "/100")

2 answers

Hey, as far as I know numbers get automatically turned into strings when printed, I am not a 100% sure it is this way (let me know if it works) but I am pretty confident this is how you do it. Let's say you wanted to print the health of a humanoid.

Health = Humanoid.Health
print(Health)

now, if that doesn't work (it should), then you must explicitely tell the script to turn the numbers into a string, and you do that with the tostring function.

Health = Humanoid.Health
print(tostring(Health))

If it works please remember to accept the answer and upvote, thanks you and good luck :)

2 comments

0

You can print numbers. You can print pretty much any value.

0

You can convert anything to a string using 'tostring(value)'. If it does not work, it should return 'nil'.

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