Scripting Helpers is winding down operations and is now read-only. More info→
← Blog Home

How to teach yourself Lua

The ability to teach yourself is one of the most important skills you will ever learn. It allows you to learn not only independently, but also at a much faster rate. This ability will ultimately put you far ahead of your peers, and can separate an average Joe from a genius.


But lucky you! If you're reading this, you’re most likely already ahead of the game, assuming you want to go into programming. Don't get bogged down by all the super smart people on Scripting Helpers. This is a minority. The mere fact that, as a kid, you're taking an interest in programming is amazing, and will put you ahead of many other future programmers.

My father is currently a programmer, but he had absolutely no experience before his first class in college. Why? Because nobody had a personal computer back then. (I know, it was like the stone age or something). But now we have an actual game that makes programming fun, as well as a massive amount of documentation on the subject. We just need to take advantage of it. So, here are some tips about teaching yourself Lua.

Keep it simple

I know, I know. You want to make an FPS with fire-breathing dragons that fly around destroying buildings. But you can't have the mindset of wanting to learn that, because there's not really anything to learn, per se. It's a project, not a specific skill. You need to learn Lua, not complicated projects created with Lua.

Always start as simple as possible. There's actually a whole blog post that goes more in-depth about simplifying your problem, so be sure to check that out.

Research it

It's not that this is super hard, but a lot of people just don't do it. The Roblox wiki has a ton of information. Aside from their tutorials, which are great, it has documentation on all the properties, events, and methods of all objects.

Alt text

Maybe I want something to happen when my mouse enters a GUI, but I have no idea where to start. All I have to do it look up Frames on the wiki, look under events, and I'll see a MouseEnter event. There. Problem solved. But yet so many people don't do this.

Google is also helpful. Of course, it's more of a hit or miss with google. It can be helpful to put "for dummies" at the end to get a simpler explanation. When I was confused about Bézier Curves, a tutorial I found with google explained it to me very well.

Mess with it

This is by far the most important section of this entire post. And yet it's also what people skip more than anything else. We are far too prone to desire a quick and easy answer to our problem. While outside help certainly has its place, so does messing with code yourself.

Sometimes it's hard to actually take the time to write out code. If you understand it, you'll want to move on to the next tutorial. But the only way to get better, to truly learn how something works, is to practice it. Practice may not make perfect, but it does make progress. It doesn't matter how well you think you understand a concept, write it out, change it, mess with it. Force it to error. Then fix that error! Think of another way to do something. Switch around a value and see what happens. This is how you will improve.

Use print constantly. Seriously, people totally underestimate the usefulness of this function. Can't get your CFrame to work? print it, see what's going on. "Oh! I changed the X axis instead of the Z axis!" Not sure where a script is breaking? Use print to find where it stops working. "My event isn't firing!" The point is, use print all the time.

Application

Let's go through an example. Perhaps I want to learn about generic for loops.

local greetings = {"Hello", "Hola", "Bonjour", "Guten tag"}

for i, v in pairs(greetings) do
    --stuff
end

Okay, so we start with a table. I already know about tables, but if I need a refresher, a quick wiki search will solve any confusion.

But what is pairs? Let's look it up. Nope, that page doesn't go into much detail, and I can't totally understand it.

Let's just look up the generic for loop page. Okay, so pairs is an iterator function. I may understand their example, or I may not, but the concept makes sense. It just returns whatever is next in a list each time it's called. So the first time an iterator function is called, it might return 1. Then if it's called again, it might return 2, then 3, etc.

Scrolling down, the page gets more specific. "[pairs will] return table keys and their corresponding values." Okay. So each time it's called, pairs will return the next key/value pair in the table. Now it makes sense why it's called pairs.

Testing

We actually could have skipped a lot of the research if we went straight to this step. It would ultimately be limiting, as I wouldn't really understand generic for loops. But I would be able to use them, even if I didn't understand. That's how powerful experimentation is. And if I didn't understand the research, testing would help me understand.

local greetings = {"Hello", "Hola", "Bonjour", "Guten tag"}

for i, v in pairs(greetings) do
    print("i = "..i, "v = "..v)
end

The result:

i = 1 v = Hello
i = 2 v = Hola
i = 3 v = Bonjour
i = 4 v = Guten tag

Okay, so this makes sense. i must be the index of the table and v must be the value.

But what about this? I've seen people do this before.

local greetings = {"Hello", "Hola", "Bonjour", "Guten tag"}

for _, v in pairs(greetings) do
    print(_, v)
end
1 Hello
2 Hola
3 Bonjour
4 Guten tag

Alright, so it didn't make a difference. Perhaps I can name i and v anything I want?

local greetings = {"Hello", "Hola", "Bonjour", "Guten tag"}

for flopperderf, buggybaffles in pairs(greetings) do
    print(flopperderf, buggybaffles)
end
1 Hello
2 Hola
3 Bonjour
4 Guten tag

Great! So I can name them whatever I want. What happens if I leave out one of the variables?

local greetings = {"Hello", "Hola", "Bonjour", "Guten tag"}

for v in pairs(greetings) do
    print(v)
end
1
2
3
4

So if I leave out one of the variables, that's fine, but the first one is always the index of the table. Therefore if I want the value, I have to have both. What if I leave out both variables?

local greetings = {"Hello", "Hola", "Bonjour", "Guten tag"}

for  in pairs(greetings) do
    print( )
end
11:50:18.457 - Workspace.Script:3: '<name>' expected near 'in'

Nope, that doesn't work.

This is the process of learning by messing with code. It's just a constant series of What if I do this? What if I do that? combined with using print a bunch.

But... How do I start?

As you've probably noticed, this article was focused mainly on people who already have some experience, helping them increase their knowledge. If you have absolutely zero scripting experience, it's even easier! There's a massive number of tutorials for people with no experience.

Intro to Scripting, Scripting Cookbook, CodeTheorem's Intro to Scripting, ScriptGuider's Lua tutorials, Roblox's Videos, Roblox University, and Roblox's Hour of Code are great tutorials that will teach you a ton.

Even still, you won't improve if you don't practice.

Conclusion

Scripting Helpers can't do everything for you. There's a point where you just gotta sit down and teach yourself.

1. Keep it simple. Don't take on something two complex for you to handle, learn step-by-step.

2. Research it. There's no need for you to ask "Uhh, what was the property that did X?" Because all that information is on the wiki, and you can look it up easily enough.

3. Mess with the code. You won't get anywhere or learn anything if you neglect this. Use print constantly.

Anyways, I hope this article was helpful. Keep learning :)

Posted in Scripting Tips

Commentary

Leave a Comment

TheDeadlyPanther says: July 28, 2016
Great article! Probably one of the best and most useful posts currently on the site.
MEGALODAN01 says: July 28, 2016
Extremely useful! Thanks a bunch!
Autobots62 says: July 29, 2016
thank you so much thank to you ican finally accomplish my roblox goal to make the ultimate roblox obby and shooter :P
SHDrivingMeNuts says: July 30, 2016
too*
TheHospitalDev says: August 1, 2016
^ xD
rexpex says: August 4, 2016
Where should i start if i want to read the article, its really confusing its like i skipped 50 chapters on a book and its like i should know whats happening
medhanie320 says: August 5, 2016
usefull and great article
barkface1 says: August 5, 2016
Thanks a ton. I'm trying to start scripting. I wish that they would put up more tutorials.
Celeritas says: August 8, 2016
Awesome post! Great to stay motivated.
User#11440 says: August 8, 2016
Never learn something two complex for you to handle. Also, am I one of the smart people you were talking about :)
VisorDEV says: August 9, 2016
Thanks, this helps out alot and doesn't make me feel "alone" in the process. Working on a new Project from my Scripting skills :)
buoyantair says: August 10, 2016
Nice tutorial.
Scripter_Blan says: August 26, 2016
Ya nothing comes to me without effort. LEARN LUA Step by Step!
MsPuppyChan says: September 15, 2016
I really like your article it's really inspirational :)
BadLuke1 says: September 24, 2016
stupid
BadLuke1 says: September 24, 2016
stupid
alienantics says: October 5, 2016
You sir/ma'am/person... are my hero.
savagedragon_slayer says: October 9, 2016
this really helped
crystalclay says: October 10, 2016
I love this article! I'm teaching myself while doing small projects which will allow me to utilize that knowledge and it will help a lot. Thank you for going into detail with the research process!
DepressionSensei says: November 5, 2016
Very useful and detailed article, bookmarked.
Volodymyr2004 says: November 12, 2016
tip do NOT attempt to create an fps with flying dragons that destroy buildings
OldPalHappy says: December 12, 2016
This is a great article. Very helpful for the community.
Troidit says: January 3, 2017
Aw man, great article. I use the tactics you mentioned all the time!