Roblox > Scripting Lessons >

Lesson 11: Tables

Tables are another very important part about scripts. They are basicaly variables that can store more than 1 value.

Tables are declared like this:

tableName = {value1, value2}

You will notice when you look at this that there are two values in this table. value1, and value2. To access a specific value in a table type the table name and then a [] with the number of the value that you want to access in it.

For example: tableName[1] is value1, and tableName[2] is value 2.

Typing a "#" with the name of a table after it will return the number of values in the table. For example:


is equal to 2 because there are two values in tableName.

Tables are used a lot with for loops. For example can you guess what this does? (No fair peaking at the answer below)

for i=1,#tableName do

If you guessed that it prints all the values of tableName to the output, then you are right. This feature can be used to search tables for values and other similar things.

There are also a number of built-in functions relating to tables. You can see the wiki article for these here.

If you have any questions regarding this lesson or the functions in the wiki, please PM me or Post on the Forums.

<- Previous Lesson   Proper Formatting -&gt;
Updated on Oct 25, 2012 by Ajedi32 (Version 11)
comments powered by Disqus