How do script [ Update Version], 2022/2023
Introduction
Hey there! Today, I will be teaching you how to script from scratch - all the basics you need to know when coming to script on Roblox with a better and updated version!
[If you’re a beginner] After this tutorial, you should learn:
- Understand the very basics of scripting on Roblox.
In this tutorial, we’ll be talking about:
- Variables, DataTypes.
- Attributes, Properties.
- Math library.
- Conditions,Functions, Loops.
- Return, Remotes.
- Gamepasses,DevProducts.
- Tools,Player, Character, Animation.
- TweenService, Camera.
- ClickDetectors & ProximityPrompts.
- Mouse & UserInputService.
Anticipation and expectations
Look, like every other profession/hobbies, it doesnt take straight away to success in learning something new. It is a process, it might be short or long way, but you can’t escape the process. The result doesn’t matter. What matters is the process done throughout the way. Because during that, you’re learning how to be better, and how to struggle with multiple conditions.
So, what does scripting mean?
When you’re scripting/programming, you’re actually manipulating, customizing, and making cool stuff using an existing program/system. Meaning, you’re providing instructions to your computer - telling it what to do, and how do you want to acheive your goal by doing what I mentioned above.
On Roblox, you could think of scripting
as the Scenes in the back of each game on the platform.
And every game you see on Roblox, was made by people who scripted
and wrote codes
to run these games properly and playable.
Let’s dive into the sea!
So now that we know what we are doing and what stands behind it, we should start learning how to implement and write our first codes which would eventually lead to a long process that at the end, we’ll be ready to make our own games.
Part 1
Variables
A variable is basically a name[ string ] that can hold / have any value.
Very impotant! There are few keys that you can not use as variables, and those are:
Defining a variable should look like this:
local myVar = 5
--OR
myVar = 5
The difference between the 2 ways is: first one is local
, whereas the second one is global
[ which is slower by the way]. You could see that difference in the following example:
--Local Variable
local myVar = 0
for k = 1,10 do
local myVar = 0
myVar += k
print("myVar now equals to: "..k) -- 10
end
print("myVar now equals to: "..myVar) -- 0
--Global Variable
myVar = 0
for k = 1,10 do
myVar += k
print("myVar now equals to: "..k) -- 10
end
print("myVar now equals to: "..myVar) -- 55
DataTypes
A DataType in programming means classifying values and specifying their variables with value types. [For example : string, number, boolean, table, nil]. In addition to that, it also determines what type of mathematical, relational or logical operations can be applied to it, which would eventually lead us to different results depending on what we used.
Data Types On Roblox!
On Roblox, we have 6 types of Data Types, let’s review them and see what they are and what they do.
1. Nil
On Roblox, the nil
value means nothing/doesn’t exist. And what it does is remove the object/value from your game or and/or its reference. Moreever, luau [ Roblox language] has a garbage collector which basically removes any data/references which are not used/accessible by any script. Let’s see an example:
local part = Instance.new("Part")
--Properties
part.Name = "Test"
part.Color = Color3.fromRGB(85, 255, 255)
part.Size = Vector3.new(1,1,1)
part.Transparency = 0.5
part.Position = Vector3.new(0,5,0)
--Parenting it
part.Parent = workspace
print(part) -- Test
--Delay
task.wait(3)
--Re-parting it and removing it, so you can't see it.
part.Parent = nil
print(part,part.Parent) -- Test, nil
--Removing part reference
part = nil
print(part) -- Nil
As you can see, the code above creates a part, changes some of its properties, parents it into workspace, and then to nil, and then setting the part itself to nil, and as you should’ve noticed :
Although we parented the part to nil, we still had its reference, hence that’s why the second print returned us the part, whereas the last print returned nil because we removed the part’s reference.
2. Boolean
The boolean
value can have 2 values - true
or false
. Notice that if you set the bool’s value to nil
, it would return you false
. An example:
local value = Instance.new("BoolValue")
value.Name = "Boolean"
value.Value = nil
value.Parent = workspace
print(value,value.Value) -- Boolean, false
3. Numbers
A number value represents any possible number. Including decimals, zero and negatives. It is also important to know its limits:
Range: from : -1.7 × 10308 to 1.7 × 10308 (around 15 digits of precision)
An int value represents any possible integers
. Including zero and negatives.
Trying to set an intvalue’s value to a decimal number, would give you the following error:
Unable to cast string to int64
.
It is also important to know its limits -
Range: from: -2 ^ 31 to 2^31 - 1.
Note:
When you’re trying to set an int/numbervalue’s value to nil
, it’d return 0
. And when you’re trying to set an intValue
’s value to a decimal, it’d round that number to its closest int value. [ see example below].
The following example is simply creating an IntValue
and a NumberValue
, and tries to set its values to different time of values.
------Creating an IntValue-------
local Int = Instance.new("IntValue")
Int.Name = "Int"
Int.Value = 10
Int.Parent = workspace
------Creating a NumberValue-------
local Num = Instance.new("NumberValue")
Num.Name = "Num"
Num.Value = 10
Num.Parent = workspace
------Setting their values to different values-------
Int.Value = nil
print(Int.Value) -- 0
Int.Value = 10.5
print(Int.Value) -- 11
Num.Value = nil
print(Num.Value) -- 0
4. Strings
A string value is simply a sequence full of characters [ letters, numbers and symbols].
Declaring Strings On Roblox:
There are multiple ways to define/delcare a string on Roblox, I will show 3 of them:
1.double quotes ("), look at the example below to see.
2.single quotes ('), look at the example below to see.
3.double brackets ([[), look at the example below to see.
The following example simply delcares multiple strings in all 3 ways mentioned above.
------------Defining Strings------------
local String1 = "Hey! This is a string!"
local String2 = '1+1 = 2! This is a string too!'
local String3 = [[
"Hello!"
'Hello!'
]]
------------Printing Strings------------
print(String1) -- Hey! This is a string!
print(String2) -- 1+1 = 2! This is a string too!
print(String3) -- "Hello!"
-- 'Hello!'
Converting Strings → Numbers and vice versa.
There are multiple times when you would prob need to convert a string into a number [ or vice versa], a fresh example would be: Say you have a TextBox
which lets you redeem players’ IDs, and you want to use the input to do something. You notice that that number is passed as a string. Not as a number.
That’s where tonumber()
and tostring()
get involved.
tonumber()
This function would convert your string into a number [ if possible].
tostring()
This function would convert your value into a string [ if possible].
The following example would try to convert both a string → number, and number → string.
local Number = 1
local String1 = "Hello"
local String2 = "1"
print(Number + String2) -- 2! Since `String2` can be defined as a number , althought its variable defined as a string.
print(Number + String1) -- Error! attempt to perform arithmetic (add) on number and string.
print(tonumber(String2)) -- 1
print(tonumber(String1)) -- nil
print(tostring(Number)) -- 1
print(tostring(String2)) -- 1
Combining Strings
To combine 2 [ or more] strings, you’ll need to use this: ..
. See example below:
local String1 = "Hello"
local String2 = "World"
local String3 = 5
print(String1.." "..String2) -- "Hello World"
print(String1..String2) -- "HelloWorld"
print(String1..String3) -- Hello5
5. Tables
Think of tables as big containers which contain multiple types of variables [ except for nil].
There are ‘2 types of tables’ that you’ll see:
Arrays
A list with an order, containing multiple types of values. An example:
local myArray = {"Hello",1,game.Workspace.MyPart,true)
As you can see, myArray
contains 4 types of values: string
, number
, object
and a boolean
[ accordingly].
Notes:
To get a value/ read from an array, simply put a []
and the index within. For example:
print(myArray[1]) -- would print "Hello"
print(myArray[6]) -- nil, doesnt exist.
To replace an exisiting value within an array, with something else, you should call the index of the value you want to change, and put in within the [ ]
when calling the array, an example:
local myArray = {"Hello",1}
print(myArray[1]) -- "Hello"
myArray[1] = 2
print(myArray[1]) -- 2
Functions For Arrays:
There are multiple functions to work with when using arrays, here is the list of them:
-table.clone()
-table.find()
-table.getn()
-table.maxn()
-table.move()
-table.pack()
-table.sort()
-table.clear()
-table.concat()
-table.create()
-table.freeze()
-table.insert()
-table.remove()
-table.unpack()
-table.foreach()
-table.foreachi()
-table.isfrozen()
I will exaplain 4 of them:
1.table.getn(): returns the amount of items your array has. An example:
local mytab = {1,2,6}
print(table.getn(mytab)) -- 3
2.table.insert(): inserts the provided value into the provided table. An example:
local mytab = {1,2,6}
print(mytab[4])--nil
local newValue = table.insert(mytab,5)
print(mytab[4]) -- 5
3.table.concat(): returns all the values in your array, separated with the given symbol. An example:
local mytab = {1,2,6}
print(table.concat(mytab,"!")) -- 1!2!6!
4.table.clear(): clears all the values from the given table. Meaning it sets those values to nil. An example:
local mytab = {1,2,6,"hey"}
print(mytab[1],#mytab) -- 1,4
table.clear(mytab)
print(mytab[1],#mytab)-- nil,0
Iterating/Looping over arrays:
To loop over an array, simply use the global ipairs() [or pairs(), depending on your use] function in a for loop. You should also remember that arrays have numerical indices, which means - you can also use a numeric for loop from 1 to the length of the array (#array).
An example:
local tab = {4,3,2,1.2}
for index,value in pairs(tab) do
print(index,value)
end
print("------------------------")
for index,value in ipairs(tab) do
print(index,value)
end
The difference is that if there was a nil value within the table, pairs
would continue counting, but without the nil index. Whereas ipairs
would stop at one index before the nil value, and won’t continue.
Dictionaries
Extention of arrays.Unlike arrays, dictionaries contain a set of key-value pairs. (where the keys can be any number, string, or object.) An example:
local dictionary = {
Key1 = "Bell", -- Key,Value
Key2 = "Steve", --Key,Value
Key3 = 500 --Key,Value
}
print(dictionary)
To replace an exisiting value within a dictionary, simply specify the key of that value within a couple of []
. An example:
local dictionary = {
Key1 = "Bell",
Key2 = "Steve",
Key3 = 500
}
print(dictionary["Key1"]) -- Bell
dictionary["Key1"] = 5
print(dictionary["Key1"]) -- 5
To add new values, simply specify a key within a [ ]
. An example:
local dictionary = {
Key1 = "Bell",
Key2 = "Steve",
Key3 = 500
}
print(dictionary["Key4"]) -- nil
dictionary["Key4"] = 5
print(dictionary["Key4"]) -- 5
Iterating/Looping over dictionaries:
Notice! ipairs
only works with arrays
, so don’t try to use ipairs
on dictionaries [unless you have made custom functions which would help you with that].
Notice! using pairs
would NOT necessarily return you the items in a specified order, it’s random.
A solution could be as the following:
--Our dictionary, containing multiple keys.
local dictionary = {
Key1 = 5,
Key2 = 25,
Key3 = 500,
Key4 = 210
}
--A table[to be an array] that will store our values from the dictionary
local values = {}
--A for loop, to loop over our dictionary and then insert the values into our 'values' array
for key,value in pairs(dictionary) do
table.insert(values,value)
end
--Using 'table.sort' to sort our values with an order. function(a,b) would determine what order we want to have
table.sort(values,function(a,b)
return a<b
end)
--Printing our 'new sorted' dictionary
print(values)
6. Enums
Enums ( stands for enumeration ) are numbers which can take on specific sets of values. To access any type of enum, you should start with Enum.
, an example:
local Part = Instance.new("Part")
Part.Name = "Block"
Part.Color = Color3.fromRGB(255, 170, 0)
Part.Shape = Enum.PartType.Ball
Part.Name = "Ball"
Part.Parent = workspace
The above example creates a new part, changes few of its properties, and then switch its shape into a Ball
. Now, we could alternatively change its shape like this:
Part.Shape = "Ball"
But this isn’t the best way, and might be a little problematic.
Now, if you’re curious, you could go and put another .
after the Ball
, and you’ll see: Name
, Value
and EnumType
. And if you try to print those, you’d get:
print(Part.Shape.EnumType,Part.Shape.Name,Part.Shape.Value) -- PartType, Ball, 0
Each Enum
has a Value
[ a number], a Name
[ string], and a EnumType
[enum].
If you want to get the entire list of available enums, you’ll need to go to the DeveloperHub.
Notes:
To get all items of an enum, use GetEnumItems()
. An example:
local PartEnums = Enum.PartType:GetEnumItems()
for index,value in pairs(PartEnums) do
print(value)
end
--[[
Enum.PartType.Ball
Enum.PartType.Block
Enum.PartType.Cylinder
]]
Properties & Attributes
In this section, we’ll be learning about Properties
and Attributes
[ custom properties].
So, what are properties?
Properties allow you to adjust and change the look & behaviour of certain objects, you can change some of them manually through VIEW
→ PROPERTIES
.In the following example, we’re changing multiple properties of a Part
:
------Inserting a Part------
local Part = Instance.new("Part")
------Editing some properties------
Part.Name = "Hey there" -- chaning its name
Part.Size = Vector3.new(5,5,5) -- changing its size
Part.BrickColor = BrickColor.random() -- changing its BrickColor to a random one
Part.Anchored = true -- setting its anchored to true, so that it won't fall from air
------Parenting it to workspace------
Part.Parent = workspace
Attributes
Attributes are custom properties which allow you to customize and edit your own properties on objects.
Attributes can be used in these cases:
To manually create an attribute, you should go to your object’s properties, scroll down until you find Add Attributes
button.
To create an attribute from a script, we will use the SetAttribute()
method, and inside, we’ll provide 2 arguments : 1.Attribute Name
, 2.Attribute Value
.
local Part = script.Parent
Part:SetAttribute("NewProperty",50)
To get an exisiting/created attribute from your object, we will use GetAttribute()
, and provite it 1 argument - the attribute’s name. [Notice, you could also use GetAttributes()
[don’t provide anything], it would return you a table of all your object attributes.
local Part = script.Parent
-----Setting the Attribute------
Part:SetAttribute("NewProperty",50)
-----Calling the Attribute------
print(Part:GetAttribute("NewProperty")) -- 50
To simply delete an attribute, set its value to nil
.
local Part = script.Parent
-----Setting the Attribute------
Part:SetAttribute("NewProperty",50)
-----Removing the Attribute------
Part:SetAttribute("NewProperty",nil)
To detect when an attribute has changed, we will use either GetAttributeChangedSignal(AttributeName:string)
or AttributeChanged()
. See the example below:
local Part = script.Parent
-----Setting the Attribute------
Part:SetAttribute("NewProperty",50)
-----Detecting Attribute Changes------
Part:GetAttributeChangedSignal("NewProperty"):Connect(function()
print(Part:GetAttribute("NewProperty"))
end)
Math Functions
In this section, we’ll be learning some of the most useful functions there are in luau math library. Let’s begin! (If you’re interested in seeing all math functions, please visit Math Library - Roblox DebHub.)
math.abs(x:number):
abs stands for absolute. Meaning it returns you the absolute value of the number.
print(math.abs(-5)) -- > 5
math.ceil(x:number):
ceil stands for ceiling. Meaning it rounds your number up
to the closest integer.
print(math.ceil(5.21)) -- > 6
math.floor(x:number):
This function rounds your number down
to the closest integer.
print(math.floor(5.21)) -- > 5
math.clamp(x:number,minimum:number,maxmium:number):
This function checks the first given number, and checks if it’s within the minimum & maximum range. There are 3 possible conditions:
A. That number is within the range. Result: we should get the exact same number.
B. That number is bigger than the maximum. Result: we should get the maximum number.
C. That number is smaller than the minimum. Result: we should get the minimum number.
print(math.clamp(1,0,10)) -- > 1
print(math.clamp(-1,0,10)) -- > 0
print(math.clamp(25,0,10)) -- > 10
math.min(x:number,…:number):
Simply returns the minimum[smallest] number among the passed numbers.
print(math.min(-5,25,-10,0,15,1)) -- -10
math.max(x:number,…:number):
Simply returns the maximum[biggest] number among the passed numbers.
print(math.max(-5,25,-10,0,15,1)) -- 25
math.random(x:number,y:number):
Simply returns a random number within the range of these 2 numbers.
print(math.random(1,100)) -- > 66
(If you’re interested to get decimals aswell, you might want to use the following:)
local random = Random.new()
print(random:NextNumber(1, 100)) -- 82.012
math.sqrt(x:number):
Simply returns the squre root ot the given number.
local number = 25
print(math.sqrt(number)) --- 5
Notice that when you’re trying to do: math.sqrt(-number)
[number > 0], this would return you nan
[ not a number].
math.pow(x:number,y:number):
Simply returns you x to the power of y.
local a = 2
local b = 5
print(math.pow(a,b)) -- 2 ^ 5 = 32
math.rad(angle:number):
Simply returns you the given angle[degrees] but in radians.
local AngleInDegrees = 90
print(math.rad(AngleInDegrees)) -- 1.5707
math.deg(angle:number):
Simply returns you the given angle[radians] but in degrees.
local AngleInDegrees = 90
local AngleInRadians = math.rad(AngleInDegrees)
print(math.deg(AngleInRadians)) -- 90
math.round(x:number):
Simply returns you the closest integer to that number.
local a = 25.666666666666666666666
local b = 25.111111111111111111111
print(math.round(a)) -- 26
print(math.round(b)) -- 25
math.log(x:number,y:base):
Simply returns you the logarithm of x, with the base of y.
local num = 8
local base = 2
print(math.log(num,base)) -- 3, since 2^3 == 8
Numbers with math.
:
math.pi: A number. Equals [ approximately] to 3.14159265359.
math.huge: A huge number. Would return you inf
if you printed math.huge
.
If Statements
If statements are conditional statements
. Meaning - code inbetween the if statement would only run under specified condition.Let’s see some examples:
local myVar = false
if myVar == true then -- if our variable equals to true, then..[condition 1]
print(true)
else -- if not, meaning it equals to false [because booleans have only true / false conditions], then..[condition 2]
print(false)
end
As you can see, when we run this code, it prints false
. Simply because the first condition didn’t happen because it wasn’t true. But the ncame the second condition [ the else
]. And checked if this
can happen, and it did.
Now, here are some tips/notes :
1.Instead of doing if myVal == true
, you could simply do if myVal
2.Do not get confused! =
is used when we set , change or define variables. Whereas ==
is used to compare between conditions.
The following example would check if the script.Parent
, which is a Part
here, is transparent or not, and act accordingly:
local Part = script.Parent
if Part.Transparency == 1 then
print(Part.Name.. " is transparent!")
else
print(Part.Name.." is visible!")
end
Loops
Before we get into what loops are. Let’s say we have a code that runs once, and we want to run it multiple times. How’d we do that? Obviously, there are several ways to do that, but we’ll focus on loops
. Using a loop will help us run our code for more than once. And that’s what loops basically do - some loop through values / objects , whereas others would just run the code multiple times.
Let’s review some of the loops we have on Roblox:
The for k = a,b,c loop.
for k = 0,10,1 do
print(k)
end
--This would print all numbers from 0 to 10.
Now, you might be wondering what are these 3 numbers, let’s have a look here:
for k = a
: Is the ‘control variable’, in fact - that would be our variable and starting point.
b
: Is the end value where that loop should stop at.
c
: The increment value. By what number, do we want to increase/decrease the count.
Let’s now see an example where we decrease
the value.
--This would not run, since we can't really increase 10 by 1 to reach 0.
for k = 10,0,1 do
print(k)
end
--This would count from 10 to 0, -1 is the value we decrease the count by.
for k = 10,0,-1 do
print(k)
end
The for index,value in pairs() / in ipairs() loops.
local tab = {1,2,3,4,nil,5,6}
for index,value in pairs(tab) do
print(index,value)
end
--[[
1 1
2 2
3 3
4 4
6 5
7 6
]]
print("------------------------")
for index,value in ipairs(tab) do
print(index,value)
end
--[[
1 1
2 2
3 3
4 4
]]
Let’s understand and review what’s going on here. So first, we have a table - containing few number values and 1 nil value. Both loops would loop through the items[values] within the table and print their index + value. If so, why do we get different results?
The answer is:
ipairs
would stop once it finds a nil value within the table.
Whereas, pairs
would just ignore that nil value and continue to the end.
As we mentioned when we talked about tables
. pairs
is a loop that would run for both types of tables, whereas ipairs
would only run for arrays
.
The While Loop
while true do
--Code here would run forever, as long as the condition is met
--Notice that without putting a delay, this would crash your game!
--That's why, you should always have a task.wait()
task.wait() -- you can choose any number you want, depending on your needs.
end
Let’s analyze this code,
so we first have this line while true do
, which basically would run forever, as long as the condition is true/met.
You might be asking, but why do we need that task.wait()
?
The answer is simple! If you tried to run a while loop
without a delay, this would crash your studio/game, and that - we don’t want.
Breaking a While Loop
local Elapsed = 0
local Limit = 10
while true do
print("Looping...")
task.wait(1)
Elapsed += 1
if Elapsed == Limit then
break
end
end
print("Loop interupped/stopped.")
Let’s analyze the code, so we first have 2 variables at the top.
Elapsed
is the initial value we’re counting on.
Limit
is the maximum number we want the counting to go on.
Next, we’re having a delay of 1 second, and then we’re adding +1 to our initial value.
if Elapsed == Limit then
break
end
This if statement
is checking if we’ve reached the maximum number we want to add to our counting, and if it did, we break the loop. Which means, the loop will stop.
Functions
In this section, we’ll be learning about all basic types of functions you’ll need to know when scripting on Roblox. You could view functions as alot of things, one common way is as machines with defined tasks
. And if we want to be a bit more accurate, functions are values that take up memory , receives thread control when called, and can be anonymous. Where the goals are portability, simplicity, small size, and scripting.
Define A Function:
local function myFunction() -- myFunction is the name of the function.
--Any code here, would run only when the function is called
end
Now, you might be asking 2 things:
1.When I run this code, it doesnt do anything, why?
2.What if I wanted to put values in the ( )
?
Parameters & Arguments
Let’s answer these questions and see how to implement it.
1.In order to make it actually do something/what the function is defined to do, you need to call the function. You can do this by declaring the function’s name.
local function myFunction() -- myFunction is the name of the function.
print("This function is now running!")
end
myFunction() -- Calling the function to begin
2.If we wanted to provide values into our function, that’s what parameters
are for!
Parameters allow us to edit and modify objects/values within our functions. You now might be wondering - how do I set parameters and use them? Let’s take a look here:
local function myFunction(String1,String2) -- myFunction is the name of the function.
print(String1..String2) -- Hello!World
end
myFunction("Hello!","World") -- Calling the function to begin
As we can see, we have 2 parameters in out function - String1
and String2
.
And you might notice that when we’re calling the function,we provided 2 values,[ in this case, 2 string values] - those are called arguments
. And it is important to match them accordingly. What I mean is:
Hello!
→ String1
World
→ String2
.
Returning data
Let’s assume we have the following function:
local function SumNumbers(n1,n2)
local sum = n1+n2
print(sum)
end
SumNumbers(1,2) -- > 3
SumNumbers(2,5) -- > 7
SumNumbers(2,5-2) -- > 5
SumNumbers(2,3)-5 -- > error
We can conclude a few conclusions:
1.We can call the function multiple times with different arguments.
2.We can’t perform any arithmetic actions with the result of the function yet.
And now, a question is asrising - how can we get the result [ the sum in this case], and perform arithmetic actions on it? The answer is return
! Returning any data we want from the function, will help us use that data later on, again and again. Let’s return sum
and see what happens:
local function SumNumbers(n1,n2)
local sum = n1+n2
return sum
end
local CallingFunction1 = SumNumbers(1,2)
print(CallingFunction1) -- 3
local CallingFunction2 = SumNumbers(1,2) + 5
print(CallingFunction2) -- 8
local CallingFunction3 = CallingFunction1 + CallingFunction2
print(CallingFunction3) -- 11
You can notice that since we’re returning data and want to use it, we’re setting our function call as variables. This also allows us to easily do our stuff much faster. We could also do this if we wanted:
local function SumNumbers(n1,n2)
local sum = n1+n2
return sum
end
local CallingFunction1 = SumNumbers(2,3)
print(CallingFunction1 / 25) -- 0.2, since 5/25 is 1/5 which is 0.2
Anonymous Functions
So far, we’ve seen functions with names. But now, it’s time to learn a ‘new type’ of functions - the anonymous functions! They do not have names, and they’re usually connected to an event / callback. Let’s take a look:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
print(Player.Name.." has arrived!")
end)
I am sure all of you have seen this event and used alot of it. What it does is basically calls an event [PlayerAdded
] which is an event for the Players
service and connects it to a function. Within that function, we can provide a parameter, which refers to the player who joined in the game. This is useful in so many cases.
Variadic Functions
Variadic Functions are functions that can accept an unlimited amount of arguments.[take for example the print()
function:
print("Hello there John! did you know that :",1,"+",1,"=",2)
print(string.format("This %s is a %s!", "post", "tutorial")) -- This post is a tutorial!
Calling a Variadic Function with Arrays
Let’s assume we had the following array local array = {2,4,8,10,12}
We could do the following:
local array = {2,4,6,8,10,12}
print( "The first 5 even numbers are:", unpack(array))
Which basically ‘gets out’ all the items from the array , and arrange them in the string.
Part2
In the comment below, since we have a 50k characters limit.
Wait! So how do I make a game?
That’s a good question! Here are some tips, that some of them are given from some successul developers on Roblox:
1.Don’t give up! Keep going!
2.Try learn from free models, see the logic behind it!
Resources to learn from
Here, I am giving you some very helpful resources which would help you understand scripting better and how to move on, step by step.
Roblox ‘DevHub’ [now named Docs]:
This is probably one of the best, if not the best resource you can learn scripting from.
Feedback
It took me about 2-3 days to make this post [ organize and work as hard as possible to make it the best I could do].
And I would be very delighted to hear from all of you, is there anything I forgot/was wrong about?
if so, it’d be wonderful if you sent me a dm , here on Roblox, and tell me what should be improved!
- It’s flawless ! I found this helpful!
- Although I am not a beginner, I like it!
- It’s very good! Feels like could’ve been a bit better, but good job.
- Overall, it’s pretty nice for beginners!
0 voters
Your feedbacks will help me improve myself for the next tutorial!