How to print("Hello world!")

Ultimate Guide to Printing “Hello world!”

Introduction

Printing "Hello world!" is traditionally the first program written when learning a new programming language. It serves as a basic introduction to syntax, output functions, and the programming environment. This guide will cover:

  • The history of "Hello world!"
  • How to print "Hello world!" in Luau
  • Variations and formatting techniques
  • Common errors and debugging tips
  • Conclusion

1. History of “Hello, World!”

The "Hello world!" program first appeared in The C Programming Language by Brian Kernighan and Dennis Ritchie (1978). It was designed to test basic output functionality in a programming environment.

Since then, it has been used across many languages, including Luau, a lightweight scripting language optimized for Roblox development.

2. Printing “Hello, World!” in Luau

Luau is based on Lua, but optimized for performance and security, particularly within Roblox. Printing in Luau is straightforward.

Basic Print Statement

print("Hello world!")

Explanation
1. print() is a built-in function that outputs text to the console.
2. “Hello world!” is passed as a string (inside double quotes " ").
3. The output appears in the Output window in Roblox Studio or the console.

3. Variations and Formatting in Luau

a. Using Single vs. Double Quotes
Luau supports both single (') and double (") quotes.

print('Hello world!') -- Using single quotes
print("Hello world!") -- Using double quotes

b. Concatenating Strings

print("Hello " .. "world!") -- Concatenates strings with '..'

Output:

Hello world!

c. Storing in Variables

local message = "Hello world!"
print(message)

d. Multi-Line Strings

print([[
Hello
world!
]])

Output:

Hello
world!

e. Printing with Escape Characters
Escape characters allow formatting within strings.

print("Hello \world\!") -- Prints Hello world!
print("Hello\nworld!") -- Prints Hello, on the first line, and world! on the next line

4. Printing with Custom Output Functions

Luau allows creating custom print functions.

a. Warning Text in Output (Roblox Studio)
Roblox Studio has warn(), which prints in orange and bold.

warn("Hello world!") -- Prints in warning format

5. Handling Common Errors in Luau

a. Forgetting Quotes

:x: Incorrect:

print(Hello world!)

:white_check_mark: Correct:

print("Hello world!")

b. Using + Instead of … for String Concatenation

:x: Incorrect:

print("Hello " + "world!") -- Error: Attempt to perform arithmetic on a string

:white_check_mark: Correct:

print("Hello " .. "world!")

6. Conclusion

There are many more ways and options you can do to show “Hello world!” in the console or output, but I didn’t want to bombard you with information. As you can see printing "Hello world!" in Luau is simple but opens the door to learning more about strings, debugging, and printing in different environments. Whether you’re developing a Roblox game or experimenting with Luau, mastering print() is a great first step!

25 Likes

This was really helpful! I wish you will make more tutorials like that. Now I know more about Luau! Thank you!

7 Likes

I just want to take a moment to genuinely thank you for putting together such an incredibly well-thought-out and detailed guide on printing "Hello world!" in Luau. It’s so refreshing to see a post that not only covers the basics but also provides historical context, variations, and debugging tips. This kind of resource is invaluable, especially for beginners who are just starting their journey in programming, and even for experienced developers who appreciate a structured and thorough approach to the fundamentals.

First and foremost, I really appreciate that you began with the history of "Hello world!". It’s something that many programmers take for granted, but understanding its origins in The C Programming Language by Kernighan and Ritchie gives it a much deeper significance. It’s fascinating to see how this simple phrase has remained a universal rite of passage across countless programming languages for decades. By including this background, you added an extra layer of meaning to an otherwise basic concept, making the learning experience more enriching.

Your explanation of printing in Luau was incredibly well-structured. I love how you didn’t just say, “Here’s how you print ‘Hello world!’” and leave it at that. Instead, you took the time to break it down step by step, explaining the function, string syntax, and output behavior in a clear and digestible way. That kind of detail really makes a difference for someone who is new to coding or transitioning to Luau from another language.

Beyond the basics, I also really appreciate how you went the extra mile by covering different formatting techniques. The comparison between single and double quotes, the explanation of string concatenation using .., and the introduction to multi-line strings were all fantastic additions. These might seem like small details, but they’re actually incredibly useful when writing scripts in Roblox Studio. Being able to format text correctly can make debugging and output management much cleaner, and I love that you took the time to cover it all in such an easy-to-understand way.

Another thing I found really valuable was the section on escape characters. It’s something that can be tricky for beginners, so highlighting its importance was a great decision. I did notice this example in your post:

print("Hello \world\!")

From my understanding, the \ character in Luau is used for escape sequences (like \n for a new line), but \w isn’t a recognized escape sequence. Was this intended as an example of incorrect syntax, or were you demonstrating a specific formatting technique? I’d love to hear your thoughts on that!

Additionally, I really liked that you included warn(), since a lot of developers overlook it when debugging in Roblox Studio. Since warn() formats the output differently by displaying it in an orange, bolded style, I was wondering—does using warn() have any noticeable performance impact compared to print(), especially when handling a large volume of output? I’ve always been curious about that and would love to hear your insights.

And of course, I can’t forget to mention the debugging section! Including common mistakes, such as forgetting quotes and using + instead of .. for concatenation, was such a smart move. These kinds of errors can be frustrating for beginners, and having them laid out so clearly with corrections is incredibly helpful. The way you structured this guide ensures that readers not only learn how to print "Hello world!" but also avoid common pitfalls along the way.

All in all, I just want to say thank you again for taking the time to put this together. It’s clear that a lot of thought and effort went into making this post informative, structured, and beginner-friendly. Guides like this help make programming more accessible to newcomers, and I truly appreciate the depth of information you provided. Your passion for teaching and sharing knowledge really shines through in this post, and I look forward to reading more of your insights in the future! Keep up the amazing work!

6 Likes

Jobs bro, jobs.

7 Likes

In Luau, there is no escape sequence for \w, so it would just print: Hello world!
But, the reason I added it in there, just because I wanted to show as many possible ways to print Hello world and this demonstrates a way (not a good way) but a way to do it, using escape sequences.

Both print() and warn() could slow down your game, if of course spammed, but technically speaking you would probably see more performance issues using warn() instead of print(), now of course we are not talking MAJOR issues, we are just talking small. They are both lightweight functions in Roblox, so they don’t risk any if none performance to use, if used for there purpose, to debug when developing.

Thank you for your questions and appreciation for my post :smiley:

2 Likes

I just wanted to drop by to express my sincere gratitude for this incredibly well-structured and thoughtful guide on printing “Hello, world!”

It’s not every day that you come across a tutorial that takes such a fundamental concept and presents it with this level of clarity, depth, and historical context

2 Likes
local letters =  "abcdefghijklmnopqrstuvwxyz1234567890!?<>,.;':\"[]{}()"

local str = letters:sub(8,8):upper()..letters:sub(5,5)..letters:sub(12,12)..letters:sub(12,12)..letters:sub(15,15).." "..letters:sub(23,23):upper()..letters:sub(15,15)..letters:sub(18,18)..letters:sub(12,12)..letters:sub(4,4)..letters:sub(37,37)
print(str)

[the md-fg emoji]

3 Likes

I love it, this is definitely another way to do it :joy:

2 Likes

Do string interpolation and string.find next

local hell = "hell"
local world = "world"

print(`{hell}o {world}`)
2 Likes

You forgot to showcase this way:

local function cursedDecode(msg, i, output)
	if i > #msg then return table.concat(output) end
	output[i] = string.char(bit32.bxor(msg[i], 42))
	return cursedDecode(msg, i + 1, output)
end

print(cursedDecode({98, 79, 70, 70, 69, 10, 125, 69, 88, 70, 78}, 1, {}))
2 Likes

I know one that is perfect!

local Hello = "Hello"
local World = "World"
print(string.format("%s %s!", Hello, World))
1 Like

Even better

string.format("%l", "%u", "Hello", "World")
1 Like

Wow, this post is incredibly well-written and informative! I truly appreciate the effort you put into crafting such a thorough guide on printing “Hello world!” in Luau. It’s not just a simple tutorial—it’s an insightful introduction to both the historical significance of “Hello world!” and its practical applications in programming.

One of the best things about this guide is its structured approach. It starts with the history of “Hello world!”, which provides important context about how this simple program has been a staple in programming education for decades. This really helps beginners understand that even the most basic programs have a rich history and purpose beyond just printing text. The transition from history to actual implementation in Luau is smooth and well-organized, making it easy for both newcomers and experienced developers to follow along.

I particularly liked how you broke down the print function step by step. Explaining that print() is a built-in function and that "Hello world!" is a string helps reinforce key programming concepts like function calls and data types in an easy-to-understand manner. For someone new to Luau, this is an excellent way to get comfortable with the syntax while also learning about how output works in Roblox Studio.

The variations and formatting section was especially useful. Many beginner guides simply show the print("Hello world!") command and move on, but you went the extra mile by demonstrating different ways to structure and manipulate output. The examples using single vs. double quotes, concatenation, variables, multi-line strings, and escape characters are incredibly valuable. This not only helps readers grasp different ways to print text but also introduces them to fundamental string manipulation techniques that will be useful in real projects.

Additionally, the explanation of custom output functions, particularly the use of warn(), is a fantastic touch. A lot of beginner programmers don’t realize that different output functions can serve different purposes, and highlighting how warn() works in Roblox Studio adds extra depth to the guide. Understanding how to differentiate between standard output and warnings can be really helpful when debugging scripts.

The section on common errors was another highlight. Learning from mistakes is one of the best ways to grow as a programmer, and pointing out common pitfalls—like forgetting to use quotes or incorrectly using + instead of .. for concatenation—can save beginners a lot of time and frustration. It’s great that you not only identified these mistakes but also provided clear corrections and explanations for why the correct approach works.

Overall, this post is an outstanding resource for anyone starting out with Luau. It’s detailed without being overwhelming, educational while remaining approachable, and full of valuable insights that go beyond just printing text to the console. Even as someone already familiar with programming, I found this guide to be a great refresher and a reminder of how much depth can be found in even the simplest commands.

Thank you for putting this together! It’s posts like these that make the DevForum such a great place to learn and grow as a developer. I’m sure many people—whether beginners or experienced coders—will benefit from reading this. Keep up the amazing work! :rocket:

2 Likes

I can’t believe someone really put so much effort into making the pointless tutorial.


This post is literally 441 words!

How are there more paragraphs than sentences?

1 Like

It’s also possible to do

print "Hello World"

without any parentheses. In the older versions of Roblox, the default script would do this instead of with parentheses.

The shortest script will be:

print'Hello world!'

Actually u can avoid ‘()’ if u will not use more then one value for example:

part:GetAttribute'att'
or another
instancevalue:GetProperytChangedSignal'Value':Connect(blablabla)
1 Like

How to print hello world.
Step 1: Add a script to SSS.
Step 2: Playtest the game.

local A = "A"
local B = "B"
local C = "C"
local D = "D"
local E = "E"
local F = "F"
local G = "G"
local H = "H"
local I = "I"
local J = "J"
local K = "K"
local L = "L"
local M = "M"
local N = "N"
local O = "O"
local P = "P"
local Q = "Q"
local R = "R"
local S = "S"
local T = "T"
local U = "U"
local V = "V"
local W = "W"
local X = "X"
local Y = "Y"
local Z = "Z"
local a = "a"
local b = "b"
local c = "c"
local d = "d"
local e = "e"
local f = "f"
local g = "g"
local h = "h"
local i = "i"
local j = "j"
local k = "k"
local l = "l"
local m = "m"
local n = "n"
local o = "o"
local p = "p"
local q = "q"
local r = "r"
local s = "s"
local t = "t"
local u = "u"
local v = "v"
local w = "w"
local x = "x"
local y = "y"
local z = "z"
local one = "1"
local two = "2"
local three = "3"
local four = "4"
local five = "5"
local six = "6"
local seven = "7"
local eight = "8"
local nine = "9"
local zero = "0"
local point = "."
local comma = ","
local colon = ":"
local semicolon = ";"
local exclamationMark = "!"
local questionMark = "?"
local asterisk = "*"
local apostrophe = "\'"
local quote = "\""
local space = " "
print(H .. e .. l .. l .. o .. space .. w .. o .. r .. l .. d .. exclamationMark)

I spent 20 minutes i’ll never get back making this

1 Like

i just started making the next Skyrim, all with my knowledge from this post! truly a blessing!

ROCKET SHIP EMOJI SPOTTED, CHATGPT USER

1 Like