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

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

Asked by 6 years ago
Edited 6 years ago
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 :)

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

2 answers

Log in to vote
2
Answered by 6 years ago

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)

0
Thank you! DanielGamerXD 9 — 6y
0
It is a variadic function :3 User#5423 17 — 6y
0
Good to know! EpicMetatableMoment 1444 — 6y
Ad
Log in to vote
3
Answered by
fredfishy 833 Moderation Voter
6 years ago
Edited 6 years ago

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.

1
I see we both had different solutions to this question. EpicMetatableMoment 1444 — 6y
0
Yours is better and you beat me to the post (by literally less than a second by the timestamps.) fredfishy 833 — 6y
0
Thanks :) DanielGamerXD 9 — 6y
1
.. can concatenate numbers and strings (any other data types throwing an error), so in this case the tostring is unnecessary BenSBk 781 — 6y
View all comments (8 more)
0
@Dandystan, please downvote my answer because I can't do it myself fredfishy 833 — 6y
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. BenSBk 781 — 6y
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. fredfishy 833 — 6y
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" User#25115 0 — 6y
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. User#25115 0 — 6y
0
Just delete your answer or make edits if you really think it's bad. You're very smart User#24403 69 — 6y
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? fredfishy 833 — 6y

Answer this question