Different Data Types

Learn about different data types for variables and what they do.

by Daniel_Earl4

Author Avatar

#Introduction

Hello so in this tutorial im going to show you the different data types for variables.

There are many different types of data types in lua which are used to store many different things like a players money count, checking if a condition is met and the list goes on. The following is a list showing all data types, an example, a description, and why we use them.

#String String represents text, such as words or sentences, including letters, numbers and punctuation. String values are surounded by quotation marks.

Examples:

"Hello, world!"

"Good morning"

"I am a roblox coder!"

Common uses in roblox: To make characters talk.

#Number

Numbers represent numerical values, which can be used to hold counts, preform mathematial equations, and represent unites of measure.

Examples:

42

3.14159

-3.0

Common uses in roblox: Hitpoints, amounts of money, timers.

#Table

Table represents pairs of items. The first item is called the "index" or "key." The second item in a pair is called its "value." In the example below, the keys are types of fruit, and the values are their colors. Tables are declared with bracket, like these: {}.

Examples:

{apple = "red",
banana = "yellow",
pear = "green"}

Common uses in roblox: A complex object, like a vehicle, or a list of items and their properties.

#Userdata

Userdata is a pointer, or reference to an object. The Userdate doesnt contain information itself, but it points to an object.

Examples:

game.Workspace

Common uses in roblox: Working with special objects, like the Workspace.

#Boolean

A single value of 1 or 0. True or false. Used in logic.

Examples:

true

false

Common uses in roblox: Whether or not a player has defeated a boss.

#Nil A special type of value that indicates that no value has been assigned.

Examples:

nil

Common uses in roblox: Creating variables in advance, before you know what they will contain.

#Function

A function is a set of instructions that have been grouped together and givin a name. Instead of writing the same instructions multiple times, you can group them into a function, then "call" the function to execute those instructions whenever you want. There is a special kind of function called a "method." Methods perform an action on a variable.

Examples:

function hamburger()
   print("hamburger")
   print("I am a food")
end

Common uses on roblox: Printing things, defining how an object behaves.

So thats all the types of data in lua i hope this helped and cleared up some things anyway have an amazing day bye!

View in-game to comment, award, and more!