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

[SOLVED] How to print two things at the same time?

local Jogador = game.Players.LocalPlayer
local Char = Jogador.Character
local Humanoid = Char:WaitForChild("Humanoid")

if true then
	print("Vida Carregada! HP Atual:")
	print(Humanoid.Health)
end

I want to know how to print the phrase "Vida Carregada! HP Atual:" and the value of the Health in the side of the phrase at the output, so i can read both of them in the same line, how can I do it?

Thanks and sorry for my English, I dont speak it very well :)

1 comment

0

Don't use "if true then", it's not useful in this situation. If the script is false it wouldn't run anyways.

2 answers

✓ Accepted answer

##Question

How to print two things at the same time?

##Answer The print function will output any number of arguments you pass. e.g. print(1, 2, 3)

###Code Example

print("Vida Carregada! HP Atual:", Humanoid.Health)

(If this helped you please press accept answer)

3 comments

0

Thank you!

0

It is a variadic function :3

0

Good to know!

See edits below and please downvote

The .. operator is for concatenating strings.

print("hello, " .. "world")

The tostring() function converts things that aren't strings (e.g., numbers like Humanoid.Health) to things that are

print(tostring(5))

Normally when you call print it automatically calls tostring on what you give it

If you want to print two things at once, you need to handle it yourself

print("Vida Carregada! HP Atual:" .. tostring(Humanoid.Health))

Edit

Don't use this use the other one, but it's still useful to know how tostring and .. work so I'm leaving it up.

#Edit 2

.. has an implicit tostring as well, apparently, effectively making this answer pointless.

#Edit 3

.. doesn't have an implicit tostring, it just apparently works with numbers.

If this answer doesn't go negative quick I'm just going to delete it for the sake of anybody who might stumble across it in the future and think it's anything but misinformation and LIES.

12 comments

1

I see we both had different solutions to this question.

0

Yours is better and you beat me to the post (by literally less than a second by the timestamps.)

0

Thanks :)

1

.. can concatenate numbers and strings (any other data types throwing an error), so in this case the tostring is unnecessary

0

@Dandystan, please downvote my answer because I can't do it myself

0

your answer is fine, your second edit is incorrect though (apparently). print("foo" .. newproxy()), print("foo" .. nil), print("foo" .. {}) etc. will error. Only numbers and strings work.

0

This is without a doubt the worst contribution I've ever made to this website. Everything about the answer is wrong, even the edits correcting it. Pls downvote for the sake of future soles who may stumble across this.

0

And I quote: "If both operands are strings or numbers, then they are converted to strings according to the rules mentioned in §2.2.1"

0

Don't ask for downvotes, and don't delete your answer. These comments and your edits will still show new scripters the correct methods and not only that, but how to learn from past mistakes.

0

Just delete your answer or make edits if you really think it's bad. You're very smart

0

Ok but if we're leaving it up, can somebody PLEASE upvote the other answer so it doesn't have THE SAME RATING as the actually correct one?

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