Data Types and Properties | Tutorial

Yo, hope you’re having an amazing morning/night/evening/afternoon. Before I get started, you should check out my other tutorial:
Referencing and Hierarchy in Roblox | Tutorial

Anyways, lets get started.

So what is a Data Type?
Well, simply put, different types of information. For example, when having a conversation with a friend, you exchange different types of information:
“Yo! XOLT, how old are you?” → “I’m (16)” (Example)
The same thing will happen with computers, where you give it different types of information.

Here’s a few different types of data

Strings (or Text)
What I’m typing right now! Characters, Text.
Text is wrapped in quotation marks (“,”) of double brackets for multi-line strings.

“Single Line Strings”
[[Multi 
Line
Strings]]

Numbers
01234…
Probably the easiest to understand, in scripts, they’re represented literally; Just a number

local num1 = 1
local num2 = 3

Don’t worry if you don’t understand why I’m putting “local”, I’ll explain in the next tutorial over variables.

Booleans
True or False, Binary 1,0
These represent yes or no
In script, (true, false)

local AmIMale = true
local AmIFemale = false

Nil!
Literally nothing.
This data type is useful in situations where you are checking for existing data. Where nil would be present if there is no data, or the data would be present if there is data.

Tables
Now this one holds information; Where the information is incapsulated inside two squiggly brackets {}.

There are two types of tables, arrays, and dictionaries.

(Table and Array are interchangeable)

Arrays
Hold information using a key-value relationship but you can only change the value. The “keys” are numbers that can be used to reference the values that are held in them. (Values are separated by commas)

local myTable = {“Bob”, 17, true}
local name = myTables[1] -- Back to our referencing tutorial; Format for this is table[key] -> value

Dictionaries
These are different from arrays in that you can specify keys, but they have to be unique for each new key.

Correct me if I’m wrong here, but your keys can be strings or text outside of quotations but not booleans, tables and numbers

local myDict = {
[“keyHere”] = “value”,
[LikeThisEither] = “value”,
}
myDict[“keyHere”] -- -> “value”
myDict[RandomKey] -- -> nil

DICTIONARIES AND ARRAYS CAN BE IN THE SAME TABLE (Thank you, @sjr04 for correcting me)

{ “RandomVal”, [“NewKey”] = “NewVal” }
 --A mixed table; Will not error.

Roblox Unique Data Types
These data types are unique to Luau (Roblox’s version of Lua, the programming language that you script in) Here are a few examples:
Vector3: Positional Value of 3d objects
Instance: Object like Part or GUI element
Color3: Color value
Udim2: Positional value for 2d objects (GUI)
Many more, but I can’t explain them all

Now Properties.

Properties are data types of an Instance, or Object that describe different features of the object. Think of them as features of a person.
Bob.Name = “Bob” Where Bob is the person
or Bob.Age = 17
Bob.Male = true
Bob.Children = nil
Bob.Parents = {“Mary”, “Jerry”} - -Standard array because I didn’t specify a key.
These are all properties of Bob

Please reply with any questions or if you want me to clarify anything at all! Thanks for reading.

Next tutorial: Variables, since we’ve covered data types

3 Likes

This is actually incorrect, you can totally have mixed tables. It’s generally not a good idea though, because of iteration stuff, but even stock functions return mixed tables (e.g. table.pack, returns array with n field), but you should be traversing arrays using ipairs anyway, so this doesn’t really apply for table.pack.

Luau*

2 Likes

I didn’t know that actually, could’ve sworn if threw an error, but mixed tables do sound familiar. Thank you for the correction I’ll fix the post.