Transcripts
1. Introduction to my Roblox Class: Hello, I'm Nico, also known
as Calvin draw and welcome to my beginner class for roadblock scripting here on Skillshare. In this class, you will learn your first steps into
making games with Roblox. Even complete beginners
are welcome here, as there is a Lua introduction
included in this class. After you've familiarized
yourself with Lua, we'll look at some
basic Roblox concepts such as click detectors, changing positions and
the Touched event. And of course, way, way more equipped with
that knowledge. You will then go on to
making your project. Your first ONE game, which is going to be an RB. You can use all you
learned and more, let your creativity run wild. In the end, there's
even going to be some additional
intermediate topics which are going to
be really useful for Romanovs game
making as well. So what are you waiting for enrolling in this class now and begin the first steps to creating awesome
games and Roblox. I'll see you in
the first lesson.
2. Overview of the Class: All right, Welcome to the
beginner Roblox cores. And this is going to be
a short little overview on what you can expect
in this course. The first of all, there
is a low introduction included in this course, which is gonna be
very, very useful. So if you've never
scripted in Lua at all, I highly, highly recommend
going through this. This is going to save you hours of headache because you
will not be able to make proper games
and Roblox if you don't know at least a little
bit of loop after loop, we'll talk about
the Roblox Studio. We're gonna talk about
referencing parts, the different types of scripts. We're going to look
at some events, some functions, or add movement. We're even going to take a look at a little bit of force and constraints when they talk about the difference between
players and characters, we're going to make a
leaderboard collectible parts, adding a trail to the player
and a few more things. After we're done with the
basics, we're going to make a custom game which
is gonna be an OB, and that's gonna be
really awesome as well. After the RB, I also have a few intermediate
topics that we'll cover, such as publishing the game, adding GUI images, storing the data with a
data storage service, and a few more
things that can be very useful as well
throughout the course. For every lecture, you
will get an RB Excel file. So you basically didn't
get a snapshot for every single lecture in terms of the scripts
that we've been writing, Roblox has some pretty
powerful tools for creating. So I hope you're going
to enjoy the journey of making your own
first Roblox game. I'll see you in
the next lecture. So, yeah.
3. (Lua) Installing Roblox Studio: Alright, welcome to
the Roblox course. And in this first lecture, we will be installing
Roblox Studio onto your PC. If you have the roadblocks
Player installed in theory, Roblox Studio should
also be installed. However, if this
is not the case, you can navigate to
roblox.com slash create and just click
on start creating. It will then check if you
have Roblox Studio installed. It should then have
a pop-up if it isn't stopped so that
you can start it. And if you haven't installed it, then you can just
download the studio. This is just an EXE
file, and if you start, this will then
install roadblocks onto your PC like
any other program. If you're not logged
in, then you will be reading with
something like this. So you just put in your username and your password and login, the login and then Roblox
Studio is going to start. We're just going
to maximize this. And you can see, in my case, I already have some
recent games, right? I already have some files, local files, and even
online files for you. This is probably
empty under my games. You should however,
have your place. There is always a thing
that exists and under new you can start a new game. Let's create a new game. Let's choose the base
plate over here. And then after it is loaded, you can see it has now
basically created a new place. Lots of things are popping up. I usually close the toolbox as well as the
terrain editor here. And I also, I make the right
and a little bit bigger. And I also go to View and turn on the output because this is actually
quite important. It enables us to see
certain output and we will be seeing this very
shortly in the next lectures. One thing you notice
you have this file with a little cloud over here. And if I press Control S, you can see it wants
to save my game, but it wants to save this on the Roblox Cloud
for the time being. What I suggest is
not doing this. What I recommend you
do is you go to File and either do save
to file or save to file as because this actually
makes it so that you have an RB Excel file on your local hard drive
that is actually a little bit better,
especially if e.g. you run into an issue,
you can just share your OB Excel file and then I
can take a look at it, e.g. and also you will have access,
as you can probably see, to all of the OBX files that are generated
through this course. So every one of the lectures has one RB exe file where
all of the assets, all of the scripts that we're writing, everything is in there. And you can basically
see every snapshot. Right now, even
though I have this saved on the local hard drive, I still have the Cloud. We just want to
close this place and they're going to
file open from file. And then we're
just going to open the file that we've just made. And you can see now this is absolutely only our local file. And if we were to
press Control S, and it will actually save onto our hard drive
again, really cool. In the upcoming lectures, we're first of all going
to do a little bit of a little introduction
to familiarize you with the programming
language Lua. For this really we only need the Explorer and mainly
the server script service, as well as the play button. If we were to press
the play button, you can see that all
of a sudden our game mode load and we would
actually load into this game. I can now move around
and I can jump. So this is basically there for
you to test out your game. But like I said, all of
the surrounding things, many of those buttons will not talk about them in
the loo introduction. First of all, I would just
want you to get a very, very solid foundation, Lord, this is extremely important. And then we're gonna make
absolutely amazing things. And that's gonna be for
this lecture right here. I hope you found this useful and you'll learn something new and I'll see you all
in the next lecture. So, yeah.
4. (Lua) Variable Types in Lua: Alright, so let's continue with the Lula introduction here
for the Roblox course. And in this lecture we're gonna be talking about variables. Now, variables are basically
stores for certain data. But what does this all mean? Right, we've looked
at a little bit of the surrounding
stuff over here. And now we're gonna go
in and actually create our first script and then
take a look into that. We're gonna be creating those in the server script
service right here. So we're just going to click on the plus and then you can see it already frequently
used says script. Usually when you're
creating something, you want the ones that
are not greyed out, the grayed-out stuff
is basically, uh, usually you don't want to
create these types of parts and things inside of this
container, so to speak. But we want to create a script,
so we're gonna do this. It's going to immediately
open the script. You can zoom in art here
by holding Control and then just scrolling up
with a mouse wheel, you make the smaller
by scrolling down. So that is the way that
you can zoom in here. That's very important as well. Another script here, I'm
actually going to rename this. There's a couple of
ways to do this. Right-click and you
can go to Rename. You can also just press F2 and then it's going to
prompt you to rename this. Or you can go, if you have
the properties down here, you can just go to script right here and then just call this. We're going to call
this 01 dash variables. Because this is, well, this is the first lecture, so to speak, that we're
actually jumping into this. And we're going to
call this variables. There you go. Now what's very important
here is that it already fills in this particular thing
with a print over here. So if we were to do nothing, I'm just going to delete
what I had before. If we do nothing and we
just hit play, right? What you find is that, well, nothing happens
because right now we do not have our console. We actually do need to
enable this or this. We go to View and we
want to go to output. So this is our
output and you can now see helloworld from, sent from the server. We're going to talk
about this from this script with a name, oh, one dash variables. And from line one, if we go back to the tab over here where we
have our script, we can see this is
line one, beautiful. Now we can stop
this and proceed. So I'm just going to re-add
my comment over here. We're gonna be talking
about comments and things like that a
little bit more. I just want this in at the
top of the specific script, just so that we know
we're right now in the zero-one
variables script. So the print you
don't care about. So we're just going
to select it, press Delete to delete that. And we're gonna be talking
about variable types. Now as a high-level overview, we want variables because we
want to save certain data. So maybe we want
to save a number. This could be a high score, health the mount,
anything like that. So we're just going to
say x is equal to ten. And now in this case,
every time I refer to x, this is going to
represent a number. In this case, this
represents an integer. An integer is just
a whole number, so it's gonna be two
or five, or -27. That's all fine. But if we want
something like 20.8, while that is now a float, I'm going to do this
20.8, this is a float. So when declaring this, right, when we create variables, we basically want to say
the name of the variables. So in this case, x then equals. This is the assignment operator, basically meaning
we're assigning this value to this variable. If this is all very new to
you, don't worry at all. While you're working with this, you're gonna be able to
pick up more and more on what all of this means
for the time being, you basically just can
think about it like x is just sort of a placeholder
that we put in place. And then when the
code runs right, when the script is executed, then we're like, okay, with x, they actually mean ten. While we're looking at this in the future a little
bit more in detail. I'm just going to print this out so you can see if we have a print and then a parentheses and we put x inside
of it, right? And then the closing
parenthesis, what is this going
to output this, the question is this
going to output X is like the letter X is
going to output a ten. Well, let's just play and
you will see that it outputs ten because we're outputting the value that is inside
of the variable x. A good metaphor a lot
of people use is that variables are
basically just buckets and they contain
some sort of data. There's a special type
and that is called nil. This is a special type of value, and this basically represents
the absence of any value, also called null in certain
programming languages. In this case, it is called nil. This doesn't mean
that this is zero. This means that it is
nothing but another type of variable, or the Booleans. Now, booleans can either
be true or false, sometimes also represented with one or zero, but they
are written like this. So this is a Boolean
and they can be either true or false. Now how does this look like? Well, e.g. we can say is good course and we
would of course, hope that this is equal to true. And you can see that
this also changes color. So basically, these are certain keywords or
certain variable types. They can basically
change the font color here and even marketing
this as bold. We can then have another
boolean, e.g. is grounded. This is something
that is a little more closer to something like a game. And this could be
equal to false. And you can see it also sometimes also
suggests things to us. So as we type, right, what you can see, it already
ordered suggest, Oh, this is supposed to be
false and you can hit the tab key to
autocomplete that. Lastly, we also have strings. Now we will be talking
about those in a future lecture a little
bit more in detail. But basically, strings are sort of like words and
they are always surrounded by these
quotation marks. So we can e.g. say HelloWorld. And you can see,
that's all fine, even though I have
a space in here because the quotation
marks are surrounding it, we can save the entire word. You might come
across the fact that maybe I actually
want multiple lines. Those would be many words, e.g. and the way you do this is
you can make open brackets and you can see the
closing brackets usually generate automatically. And then here you can
just type in hello, hello student, and then comma. And then you could see, I
can continue writing this. I am writing because it is fun to have multiple
lines regards. You go, but let us
now multiple lines. And that is the general
idea here, right? So to summarize here at the end, right, variables overall, our buckets of data that
contains some data, and those can have
different values and they can be different data types. It can contain a normal
number, which is an integer. It can contain float numbers, which are numbers that
have a decimal point. It could also be nu, which
is the absence of any value. You can have Booleans
and you can also have strengths where that was it
for this lecture right here. I hope you found this useful and you'll
learn something new and I'll see you all
in the next lecture. So yeah.
5. (Lua) Output & Comments: All right, let's continue
the Lula introduction here for the roadblocks course. And in this lecture,
we're going to be looking at output comments and a little bit of how to read scripts for us to
start once again, in the server script service, we're going to click
the little plus over here, create a new script. And we're going to rename
this by pressing the F2 key. And we're going
to rename this to O2 dash output comments. How about that
one? There you go. And then let's see
what we can do. Well, we can actually
keep this print. I'm just going to
actually move this down. And up here, we're going to
create our comment again. So this is going to be
output and comments. Beautiful. There you go. So we've seen this
print before and it outputs something here
down in the output. If you don't have
this once again, you can go to View and
enable it right here. So you can see this is
now enabled because it has sort of a button background. And if it's not enabled,
then it doesn't have that. So that's basically
how you enable this. And there you go. If we have this inside of
a script and we hit play, then what you will see
down in the output and see helloworld from the server. We're going to explain
this in a little bit. And then O2 output
comments three. So once again, this is because this was in the third line. Let's stop this and let's
continue with the script. But this is pretty cool already. And last time we talked
about the idea of variables. So what if we have
a health variable and that is equal to 1,000? Once again also here
you can see that you don't need the spaces
in-between this. So spaces are only particularly important
like instead of numbers, because now the
numbers are no longer connected with each other
between certain operations, you can actually put as
many spaces as you want. I usually don't recommend it. Either one space
or zero spaces is basically the preferred
way to make this readable. But yes, you can put in as
many spaces as you would like. And now instead of
outputting HelloWorld, what we can say is okay, the player's health,
there's health is. And then the question
becomes, okay, how do we, how can we then
output this thousand? Of course we could
be like, well, it's 1,000, that's great. But if we now change this to 500 because maybe we
got hit or something, this will still say 1,000. So that doesn't quite
work as we would want to if we keep this at 1,000. And we actually say,
well health, right? And then it's like,
well, obviously it's going to take this
variable here. Well, let's just
see what happens. Indeed it does not. It just says player's
health is health, which of course is not quite
what we had in mind here. What we want output is the value of this variable
and not the name. Now, if it's inside of a string. So we talked about this before, inside of the quotation marks, then this is just read
as a normal word. It's not a keyword and it's
not red as a variable. But we can actually
use the variables. That does work. There's two ways
that we can do this. We can either do a
column over here. So this is specific to the
print function in this case. So after the first
string, right, we can do a comma and
then we can say health. You can see it actually
suggested this to us. And then you just press the
Tab key to autocomplete. Then we put another comma in, and then anything after that is also going
to be displayed. So we can say HP, e.g. and now what is going to
output is player's health is, and then whatever the mount here is saved inside of
the health variable, and then HP directly after this. So let's just play and
see what it outputs. And you can see player's
health is 1,000 HP. Perfect. Now there's
actually two spaces there. So what we can actually do, just stop this and we can even get rid of this because
now in this case, this actually adds a space. This is not the only way
that you can do this. We can just copy this line. So I'm just selecting it, pressing Control C and then Control V to
paste it in again. And instead of doing
this, we can also do dot dot and then another
dot dot right here. And what this is
going to do, this, this is going to concatenate
this variable to the string. So this might be a little bit
more complicated right now. But don't worry, we'll
talk about this a little bit more in a future lecture. And also it shouldn't
be too insane. Basically, we're just saying this is a string of characters. This is a string of characters. And while this is a variable, we actually just
wanted to also add this to our specific string. So it's going to have almost
the exact output as this. But let's just see
what happens here. So if we output this, you can actually see there's
no space in between because we're literally just taking the last thing that
is here, right? So that is, and
then we're taking whatever this variable is, whatever the actual value
of this variable is, we're converting it to a
string and then we're just plopping it right next
to the S in this case. So here we do want a space. So if we just stop this
and start this again, you can then see that
the output is going to be exactly the same in this
case, except for the HP. Because once again,
come over here, that generates a
space automatically. It has nothing to do with
these spaces, by the way, don't, don't confuse
yourself with this. I can just run this. So those spaces have
nothing to do with it. It just has to do
with the way that the whole entire thing is
basically interpreted, right? So those are two ways
of outputting here. In this case, a text
with a variable as well, which can be insanely useful, not only for in-game purposes, but also sometimes for
debugging purposes. Debugging basically
referring to trying to find issues or bugs
in your scripts. And that can
sometimes help a lot. Lastly, we also want
to talk about commons, where you've already
seen the comments with the two dashes. So this is basically a one-line
comment that I can make. I can just say some
interesting things, right? So this could be for
explaining things for yourself or others to read your scripts or
things like that. Now those will only
work for one line. So if I make another line here, you can see all of a sudden
we're all sort of a comment. And you also don't need to add the dashes here at the end. This is a personal
thing that I do, so this is not needed at all. You can also just
keep it like this and everything is going
to work totally fine. There's a personal quirk of mine now where you do actually need to add more of things is
for a multi-line comments. So we can still
do the two dashes and then we can do
to open brackets. You can once again see
the closing brackets generated automatically. And then inside of here, we actually have a
multi-line comment. There you go. That's awesome. There you go. So
you can see this is now a multi-line
comment and anything in-between the brackets here is basically all we're going to
be interpreted as a comment. You can even close this with
the little arrow over here. So that's gonna be
a little bit nicer. You can even do this. And then it's going to close it. It's going to close
it like that. That's interesting. Okay,
Well, there you go. That's a very interesting
way of doing it. That's a multi-line comment. We've seen something
similar where we will look at the
back of the variables. We have seen the multiline
string over here with the same idea when
in this case is just gonna be with comments. But as I've already explained
important note, of course, all of these scripts are always available for you for download. So the scripts are
available as well as the RB XL file for each different lecture is
always available for download. So you can basically
check everything, look at it one for one. So if you might have a different thing that is
output or something like that, you can always double-check
the code, right? To summarize, once
again, we can see that the print function is a way
of outputting something. Usually you want to
output a string, right? So if you write in
print, you can see it does already suggest to it, and you can press the
Tab key inside of that, you can then start typing. Now, usually you want
to type in a string. So you want to start
with the quotation marks and then you can just
say things in there. And that is going to be output inside of the output window. And then there's
also a comments. Normal comments start
with dash, dash, and then whatever
you want to write, this is a one-line comments. Multi-line comments
work with a dash, dash and then the open brackets. Well that's gonna be it for
this lecture right here. I hope you found this useful and you'll learn something new and I'll see you all
in the next lecture. So yeah.
6. (Lua) Math Operations: All right, welcome back to the loo introduction here
for the Roblox course. And in this lecture,
we're gonna be taking a look at math operations. So for this, once again, in
the server script servers, we're gonna be creating a new
script and we're going to rename it to A3 dash maths. Because why not? There you go. Now, let's then add our little nice comment
over here, math operations. And let's see what kinds of
math operations there are. Well, of course
there is addition, that is the first one and the idea is the
following, right? So we can have a sum and
that could be e.g. 20. So this is just going to
be once again a variable. Our 20 is the value and some
is the name of the variable. And now what we can do
is we can say, well, that's some should actually
be 20 plus 50, e.g. now this should now be 70. So let's just take
a look. So if I do another print over here, and I'm going to say sum is, let's just use this one. So we're going to say sum. There you go. So
now it's going to output the sum variable. Now first, we actually
do sum equals 20. Let's actually
change this to ten. So there's gonna be
60 because that's going to demonstrate this
a little bit better. So first, we're going to
say sum is equal to 20. We say sum is equal
to ten plus 50. So what it's going to
come out and hear, some of you might say, well it's gonna be 20 plus ten plus 50 or
something like that. Let's just play and
see what happens. You can see some is 60 because the last thing
that happens here is that the variable gets assigned the value
of ten plus five. So this one is just
ignored or overwritten because code is always evaluated from the
top to the bottom. So we start at line
one and it's going to go through and go
through and go through. And then it's gonna
be, our sum is now 20, and then the next line, our sum is now 60
because I basically evaluated this expression
as ten plus 50. That's the general idea. I can also do, is I can say, well actually what I kinda wanna do is I want
to have another one. So let's just say this is gonna be the second sum
because, why not? And that is equal to sum plus
some other amount, right? So plus 50 or plus 150
can be whatever we want. And now what is
this going to be? Well, some has the value of 20. So in theory, this
should be 20 plus 150, which should be 170. So if we do this, then
we can see some is 20. Now you might say,
wait, how is the 20? Ah, well look at this. We're outputting
the sum variable and now the second sum variable. So there's always something
you have to keep in mind. So once again, if I write this, you can see it already suggests
this to us and then we can just press the Tab
key to auto-complete. And now we're outputting
the second sum variable. And now we should
see that sum is 170. Now you can also see all of the other outputs down
here in the output. That is totally fine and
you can keep it like this. However, if this gets
too cluttered for you, you can just go to the
other ones and you can simply add comments
over here to all of the print lines in the other scripts just so that you don't have the
outputs there as well. So keep that in mind. So that is addition. Let's
look at subtraction now. Can you imagine what this
is going to look like? Well, let's just do a, let's just call
this subtraction. And this is equal to, well, e.g. something like 25 -50. Is this going to work? This is going to be
a negative number. That while, I mean, let's
just see right print. And we're going to say,
this is just going to be subtraction is, and then once again comma, and then we're going to put
in subtraction once again, auto completing
with the Tab key. Let's just let this play out
and let's see what happens. And you can see subtraction
is negative 25, that is absolutely no worries. Negative numbers
are totally fine. So this works with negative numbers,
non-negative numbers, right? We can also have 150 -50
and then it's gonna be 100. So that is really cool. The next thing is, of
course, multiplication. Now this is gonna be
the question mole t. Let's just call this
multitask, gonna be fine. How does that work? Well,
this is done with a star. So this is five-star, 40 e.g. and then it should be
what should this be? 200? Yes, exactly. It's going to be 200. So this is going to
be multiplication is, and then once again, just do
this called multi over here. And this is going to do
the exact same thing. Now once again, what
I want to say here, you don't have to put
spaces in-between. You can put spaces in between,
but you don't have to. It is the same idea when you put the spaces in here as
the space is right here. Because the idea is
that this is now a multiplication operator which uses two integers in this case, you can also, of course do this. Oh, what is this going to do? Well, I mean, let's
just try this. Let's just see what happens
five times 40.5 is 202.5. That is absolutely correct, and that works as well. So you can also use
floating numbers. It basically does
that all on its own. So that's pretty cool as well. Now, division is the one thing that is a little
more interesting. Division is of course, division and that is
equal to e.g. 20/3. Let's just say that
something like this. Okay, that's interesting. So let's do division. Is, and then let's just
call this and let's see what this gets us
20/3 is I don't know. Well, it's 6.66, 666666 repeating until it
runs it up to seven. So that is degenerate idea. So keep that in mind
when you have things that don't go into
each other perfectly. So 21/3 of course,
would be seven. So if we do this, then we're
just going to get seven. That's great. But if you have something
that is not evenly divisible, then you will get
a decimal number. And also this is very important. If we tried to divide by zero. This is a thing that you may or may not have heard before. If you do add with zero, well, you're going to get infinity. So this is a very interesting
thing and this is a quirk of Lu are more or less, you can actually divide by zero. You shouldn't do. It's still like
this is something that should actually
not be a thing. And in this case you
do get infinity. Most programming languages, usually you will get an
error if this happens. So do keep that in mind. Usually you want
to make sure that you don't divide by zero. But then there's another thing that might be very interesting, and that is the modal law, also called the remainder
and this one, right? Let's just call
this a remainder. And that is equal to,
let's say e.g. the 20. And then it's going to
be a percentage sign to and that is going to
print the remainder. Remainder is, let's just print the remainder
and let's actually see what this is going to be. And then you will pretty
quickly see what this does. Let's actually do
divided by three or like the remainder of three. And then you will see the
remainder here is two. So the general idea is that
basically just going through the actual process of division and then saying
this is the remainder, I highly recommend also just
checking out remainder. This is a normal thing. I think that this should
be taught in math class. This should be a thing that
is taught in math class. And it actually can be very, very important for
certain things in programming
here in this case, because if we were to do
the remainder of two, so 20 modal O2, this is a way of
checking whether or not a number is even or odd, because in this case
it's even, right? So if we just play this, We're gonna get a zero. So we can basically say, Hey, if this number and then we do modulo two is equal to zero, we know it's an even number. And if we do, we can
do any odd number, what, 21 in this case,
it doesn't matter. Then we're going to get one. So if the remainder is zero, then we know in this case, if we do modal O2, so if the remainder is one
with modal or two here, then we know that the number, the original number
is an odd number. If it's a zero, then it is an even number
of very interesting indeed, last but not least,
there is something called incrementing
and decrementing. This just basically
says that we want to add one to a specific number. So e.g. we can have a
number of cold five, right? And then in other
programming languages, depending on if you have
programmed before or not, you can do things
like number plus plus or number minus minus. Now what you will see is that
this does not work, okay? We can just comment
this out, right? We're just going to say they are and then this
is just gonna be like does not work because
it just doesn't work. It's just something that
lower does not offer us. However, there are
things that we can do to increment or
decrement of this number. So basically we can
say number is equal to itself plus one. This is just going to take
whatever number is defined as in this case five and then
just adding one to it, right? So once again, this
is nothing crazy, is just saying number is
equal to number of plus one. So we're just taking whatever this expression is and then
saving it back into number. Okay, That's fair. We can also have number
plus equals one. This is doing the
exact same thing. It is just a little bit more compact and written in one line. These are the exact same things they do is the exact same thing. The reason why you
want to know both of them or have
seen both of them, is that some people prefer
to do it like this. Some people prefer
to do it like this. So if you read other
people's scripts, it's very important
to have seen both. And then of course,
the same idea goes for minus in this case. Now, you can even extend
this and you can say, well what is, what
about this, right? If we do times equals, absolutely number, maybe we
wanna do divides equals. Does this work? That will be, I don't even know what the summer
will be there, but the shore number
now go crazy. Modulo equals actually, yes,
we can do this as well. Now this one I've never
seen like actually needed anywhere, ever. This one. There might be
certain moments where this could be useful, but yeah, most of the time
you're gonna be using these, maybe these three. And these two are
very specific things that are very, very rare. But once again, having seen this can be very important
indeed, right? To recap, math operations are just what they say
on the tin, right? It is operations that perform certain math functions
in this case, right? So summation just a plus symbol, a minus symbol for subtraction, a star for multiplication, and the slash for division. And in this case
also the percentage for the model or the remainder. So this is just normal math. Now you might say, why
do I need math in this, there are a lot of
moments where you might need some math, right? So it could be the case that maybe you have a
weapon and then has a certain effect
multiplier for damage, and then the opposing
player has certain armor. And you want to make
sure that the health or the damage is generated correctly, it's
calculated correctly. That's where all
of the addition, subtraction, multiplication,
division or that comes in. And all of it is going
to be some sort of, there's gonna be some sort of some that comes out at the end. That's gonna be
this, the damage. So Nath can actually be
very, very important. Now those are of course just
the very basics of math. But with these as
building blocks, you can already built
some pretty cool things wherever that is it for
this lecture right here. Hope you found this useful and
you'll learn something new and I'll see you all
in the next lecture. So, yeah.
7. (Lua) Relational & Logical Operations: Alright, welcome back
to the loo introduction here for the Roblox course. And in this lecture, we're
going to be taking a look at a relational and
logical operators nowadays sounds
very complicated, but once again, don't worry, we'll go through
this first of all, it creating a new script in the server script
service right here. And we're going to
call it 04 dash. Let's call this
relational logical. There you go. And once again, we don't need the HelloWorld
where we do need is for relational and
logical operators, sometimes also called relational
and logical operations. Either one pretty much works. Once again, don't
forget to comment out the print if you don't want to have it at the output be
completely swamped with spam. And then let's think about this. So what are relational one, what are logical operators? We're, relational
ones are basically, they're looking at two
values and they are basically evaluating the
relation between them. So this would be smaller than, bigger than smaller or
equal, bigger or equal. We also have equal
and also not equals. So these are the, well basically all
of the relational operators and they produce a, they produce a
Boolean value, right? So this once again means if you think back to the
variable types, this is either true or false. Now this should be
nothing insane here. Of course, if I say, well, 20, smaller or equal to 25, there is only, it can
only be true or false. There's no fuzziness, right?
There's not like one. If it's 50 per cent small, that, that's not
what we're talking about. We're just saying, hey, is
this smaller than this, or is this equal than this? And that is the general idea. And logical operators
are operators that take two Boolean values and
they will evaluate those. Those are end OR and the NOT
operator in this case are, those are the really
important ones. There are some
other ones as well. If you are really
interested in this, you can look up Boolean algebra. That's basically the
term to take a look at. And that basically gets us
a little bit more into it. But for the time being, we're not too concerned with it. So when we think about this, we can say a test, e.g. here is three, smaller than 20. This is of course
true in our case. We can just print
this out, right? So let's just say is
three smaller than 20? And we're just gonna
print this out. We're going to print
out test over here. There you go. But let's just play this and
see what happens. And it's going to print out
true because it's three, indeed is smaller than 20. That's very interesting indeed, you can see this, evaluates this expression and makes it a Boolean
in this case true. Now we can also say, let's say tests here again,
that's gonna be fine. This is 20 is bigger than 200. This of course will be false. And then we're just
gonna do is we're just going to select this
press control C, gotten going go here, press Control V to paste it back in. And then we're just
changing this. Is 20 bigger than 200 because now we're saying
2020 bigger than 200, which of course is false. Let's just let this play again. And we will see is 20
bigger than 200 is false. That is exactly right because
this is not the case. Those are the
examples of bigger. And then the same idea applies
for smaller equals, right? Then it's just going to be
also true if it's equal. And then if this would
be equal, right? This now would be false. Right? Should make sense because, well, 20 is not smaller than
20 is equal to 20. If we were to do this, all of a sudden it
becomes true again. Hopefully that makes
sense here in this case. Now when it comes to the
equals operator, Let's e.g. say we have a string, one which is going to be hello, and then we have a string too, which is called also
hello. Why not? There you go. Then we do a comparison of this. Why not comparison? This is equal to, and
then we say string one equal two equals signs. This is the relational
equals operator which looks at these
two strings, right? And puts out a Boolean value. This is the assignment
operator, very, very easy to mistake
one for the other. But what you should get
is you can see you will get an error if you
have a only one. So this red underline here, basically you see, it's like, oh, this doesn't make
any sense for me. Absolutely no worries. Two equals signs is the
relational operator. One equals sign is the
assignment operator. Very, very important. Now print, let's
just print this and let's just print the comparison. And we should get in
theory a true, right? So we're going to have a, the first printout, is this
true, the second is false. And then here we're just
going to have a norm, just a true output. Let's just see. And we're going to see
true, absolutely amazing. So that definitely works. Now, if I change
anything in here, it even the casing, because now these are no
longer exactly equals. So what it's going to happen
false because in this case, both of these are not equal because the casing
is always taken into account because this is
a different character and therefore they're
not exactly equal. But this would be
one of those things. And don't do this. This is just an example here. So you, for you to sort
of understand this. This is sort of what
you would do, right? When you have a password
and you're like, okay, this is whatever
the person has. Typed in, and this is the
password that I stored, red. Are those equal? And then only if it's true, then you're
going to let them in. Now, don't do this, don't
save passwords like this. That's something that should be done by only by
advanced people. Very, very much so just for you to get thinking
about this, okay, this is one of those
ways where you could see a comparison
be important. Now when it comes to
the logical operators, it gets a little more
complicated here, because here we
actually want to take multiple Boolean values and put them into like put
them next to each other. And they then sort of, you know, this is a logical
extension for this. So e.g. what you could do is, let's say x is equal
to comparison. So it's going to take the
comparison value here, which is in this case
it's going to be true. And then we can put an
and operator in here. And then the second value
has to be another Boolean. So e.g. we could say, let's just get to
test in here, right? So now it's going to say, well, if the string's match
and the test is true, then x is going to
be true, right? So in this case, comparison is going to be true and test is gonna
be false, right? So this is currently what
happens here, right? Because test here is false. So if we now were to print out x is just for the sake of argument x right here
or there you go. If we do this extra be false
and you can see x is false. Why is this the case? Well, because the end
operator says that both Boolean values have to be true for the entire
expression to be true. Now once again, if this is a little bit complicated for you at the moment,
absolutely no worries. This is a thing that you just have to play around
with a little bit. So what I highly recommend
you do is you open up this relational logical script over here and you just
play around with this. What's even crazier is you can put this on as
often as you want. So I can say End true. And maybe another one
we want to say, well, 20 is bigger or equal to 50,
something like that, right? So you can see, you
can chain those together as much as you want. Once again, it might be a
little bit complicated. It is about testing this out and trying out a few
things with us, right? I'm just going to copy
this over and I'm also going to make an
OR operator over here. So this is going to
be, now it's going to be true or false. What happens with the or
means that either one or both of them have to be true for the output to be true. So in this case, true or false just means comparison is true. And then we don't
even care what about the rest because one
of them is true. This is going to be true. So we can see, Let's
just say X1 and X2, just so that we understand
that the difference is here. And if we play this, you can see x2 is true
because here we are using the or operator
and that only cares if one of them is true and then the whole
expression is true. Like I said, it's not
really an advanced thing, is just one of those
things that's not really taught early on in school. Is it basically
just formal logic? There's nothing
crazy about this. And even though it might sound a little bit intimidating,
it actually isn't. Once again, just sit down
with it a little bit, play around with this a
little bit and you will find that this actually
isn't that crazy. Now one last thing,
Let's just take the comparison
over here as well. And then what we're
going to say is that actually we want to negate this. This means that this is
actually not a test. Now, this might be
like the FREC is this, this is pretty crazy. Well, we're basically
negating this false or we're flipping it. So negating simply
means that we're flipping it from a
false to a true. Or if this was already
true then to a false. So sometimes you will
see this written like this with an exclamation
mark in the front. But in this just means that this whole thing is true, right? So this is now all of
a sudden not false, which will be equal
to true, right? Let me do this. So this becomes a little bit
more clear, right? So we're negating the
test that whatever is written in the test
variable, in this case false. And we're flipping it to true. Once again, if you don't
get this immediately, just play around with
this a little bit. I highly recommend
you really want to just type stuff out
and print stuff out and then sort of get a little bit going with
this and then be like, Okay, now you get it because
actually applying this is way more important than
just listening to me, like explain this
like ten times. It's better for you to sit
down and be like, okay, the x is this and
then the y is this, and then it's like n naught, and then just print it out. But for the sake of
argument, let's just see x3 is going to be true. And you will find
X3 indeed is true. Because once again,
comparison is true and the opposite of
test is also true. Therefore, this is true. As a quick recap, your relational and
logical operators are all about Boolean values. And basically our operations
that compare two values, two or more values
in some cases, and give you a Boolean
value from that, right, either a true or false. There's smaller than,
bigger than equals, not equals, and also the
logical operators AND, OR and NOT in this case, these simple operations actually are everything that the
computer does like. When you go down to
the lowest of low is where all of the ones and zeros that you might
have heard about before. This is all they use and, or. And then some
relational operators, that's all they
use, nothing else. So with this comes great
power actually like, as in programming, this is
why they are quite important. Once again, here at
the end, I wanted to basically give you the
impetus to say, okay, really sit down for a good ten, 20 min and just test out
like on how these work. If you have not understood them, if you understood them,
absolutely great. I was still implore
you to just try them out a little bit if you have not understood them,
try it out again. I highly, highly recommend if of course any
questions remain, don't hesitate to ask. Otherwise it's going to be this for this lecture right here. I hope you found this
useful and you'll learn something new
and I'll see you all in the next lecture. So, yeah.
8. (Lua) If and Else Statements: Alright, welcome back to the little introduction here
for the roadblocks course. And in this lecture
we're gonna be taking a look at if and
else statements. So now we're really getting
into the meat of this. Once again, in the
server script servers, let's create a new script
and we're going to rename it off five dash if and else. How about that? There you go. I'm well, once again,
I'm going to do all five if and else. Now if and else
statements are very, very interesting indeed, let's
suppose what we have e.g. is we might have a gold
amount that's gonna be 100. And then maybe we have a, maybe you have a
grade and that's going to be let's say we just barely passed 65,
something like that. And then we also have
a Boolean value. And that's gonna be,
is, of course good. And that is going to
be equal to true. Let's just suppose
that that's the case. Now the thing we can do with
if else statements is we can basically sort of interrupt the flow from top
to bottom and say, Okay, if something is
true, then do this. Or if something else
is true, then do this. So e.g. we can say
if is coarse Good, You can see it suggests
this was uneven, tells us this is a Boolean. So we're going to hit the
Tab key to autocomplete. We then say, then, once we press the Enter key, the end over here
generates automatically. And now this is
extremely important. You can see that
our cursor right here is actually indented. So this is the same
as if I were to press the Tab key and you can see
the same indent happens here. And then this is just
automatically because right now we're inside
of this if statement. And you have to
actually be cognizant of the indent writing
it like this. So I can write stuff here. I don t think it
technically is wrong, but it looks very strange. So you basically, once you're
inside of an if statement or a function which
we're going to see later and things like that. You always have an
indent and yes, if I would have another
if inside of here, instead of that,
if we would indent another type for the
sake of argument, let's just continue with this. So this is going to print something and it's
going to produce Brent. Yeah, it's a pretty good course. So there you go.
So as long as is course good is true, we're
going to print this out. Let's just play this for
the sake of argument. It is true. So, yeah, it's a pretty, it's a pretty good course. Well, let's just make sure that it also says it's a
pretty good course. But now we're going
to say false. Let's just solve
this isn't the case, but if it might be, we're going to play
and we have no output. Because in this case, everything between then and end will only get
executed if this true. And now we're really
starting to stack on those different tools. This is basically each
one of those lectures. It's another tool in your toolkit that you
need in order for you to understand
the basics that come later with
everything roadblocks. And this is one of the biggest
and most important ones, if and then else statements. So e.g. we could also think
about something like this. Let's say let's just add
another one over here. This might be something
like the toll. So maybe right where you want to cross the bridge and
the total is 150 gold. So what we can
e.g. say is, well, if our goal that we have is bigger or equal than
the toll, right? Then we can say print,
player might pass. But maybe we want to be like, well actually we don't
want to end here. So we can replace this
end with an else. And then once again you
can see it's an else. If I just hit the tap kick, I can auto-complete
and I hit Enter, it then generates
another end over here. So we can say if gold is
bigger than the toll, than the player might pass. And if this is not the case, then we can say player is
not allowed to pass, right? So then we can just hit play. And we can see, if
we look at this, player is not allowed
to pass because gold is actually smaller
than the top right. We only have 100 gold,
but we need 150. Therefore, this
gets printed out. So everything in the
else gets printed out. If this is false and everything here gets printed
out if this is true, we can also do something
like this, right? So we can say, this is now a
very crude way of doing it, but it is true, right? So we can say current gold, let's say Gold is gonna
be Armor, Gold, right? So just put outputs,
the gold as well. And what we can do
is if we pass, well, we actually want to do gold minus equals whatever
the total is, only if we actually
successfully pass, because otherwise we
actually don't wanna do it. So now let's just
see what is the goal after we do we evaluate this? Well, it's going to
be, well, 100, right? Because we haven't
paid anything. Because indeed we can
pay because our toll is, well, it's 150 here and we
can't even do anything. I'm going to make this
one-step more complicated, but you will understand
this location, let's just say home, right? So we're home right now. And if we pass, let's just
say We're gonna be downtown. Let's just say for
the sake of argument, if we don't pass, well, we don't even need to
change the location, so we can say current gold. Let's just copy this and then we can say current location. Then we can also print
out the location. Okay, Let's just play
this once again. And then we'll see, right, we're still home and we
still have 100 gold. But now what if I change
the toll right now? It actually costs 69 to pass? What's going to happen now? Well now our gold is bigger
or equal than the toll, meaning that we are
allowed to pass. Our location is
going to change to downtown and we're going to subtract whatever goal we have, like the toll from our God. So let's play this
and let's see, and all of a sudden we
can see we now have 31 gold and we are downtown. Now this is of course, nothing in the game
itself has changed. We've only changed one or
two variables in this case. But maybe you can already
see how incredibly powerful this is to have these if statements and you
can chain them together. You can put another
if statement in here. There's all sorts of
things that you can do, which is really, really awesome. This is really one of the
things that is, I mean, it's just really cool to see this sort of thing come to life. Hopefully this is a
really illustrative example of this because they've statements
and the if else statements are really,
really awesome. Now, let's say once
again, the last thing. So we have a grade over
here and let's say e.g. we want to check, okay, it has this person pass. So we can say if screen is
bigger or equal to 50, e.g. then we're just going to say, actually, let's do it
the other way round. So let's say if it's
smaller than 50, then we're going to
print a fail, right? Because then we've failed. Now we're going to replace
this with an else. But you know what Actually, when it replaces with an else, if because I want to check whether or not the
grade bigger or equal to 50 and it
is also smaller. So great is smaller
than 100 them. Then I want to do
something specific. And then I want another else, because you can chain
them as much as you want. And then this is gonna
do something else. So this is going to be printing, let's say passed over
here, that's great. And then here, if
you get 100, right, so this would happen if
you get 100 or above. But let's just think
about that for a moment. But if we have 100 or more, then we're going to say
they passed with honors. Because why not, right? Because that's really cool. So right now we got
a 65 for the grade. So we should see past B output. Let's see if this works. And you can see past
is indeed output. That's really good. Let's stop it and then go back here and actually change
this to, let's say 100. Now we should pass with on us. Let's see. Let's play this. And we can see passed with
honors. That's great. We can even go a step further. Let's just say for
the sake of argument, we want to add
another one in here. What we can do is we can
add another else if, and we can say if
greatest, bigger than 100. Now let's, let's
do it like this. Let's say else if
great is equal to 100, then we do this, right? And then we're going
to do another else. And that's basically
going to be, if it's anything but 100, and then we can say more, more than 100 is not possible. You cheated. So something like this, more than 100 is not
possible you cheated. And now if I were to do 101, all of a sudden, we're gonna get more than 100
is not possible. You cheated. So if
you don't quite understand the
logic through this, just think about this, right? What is grade right
now? Great as 101. Is this smaller than 50? Not 101 is not smaller than 50. Therefore, we go to the else if, now we're checking, is it
bigger or equal than 50? It is indeed bigger
or equal than 50. But this also has to be
true because we're using the logical operator AND right, so both of these
things have to be true for the entire
statement to be true. And because great
is bigger than 100, we're going to the else if
now we're looking Great, equal to 100, it is
not equal to 100, it is indeed 101. Therefore, we're going
to the else over here. And because we don't
have an if statement, we're just saying, okay,
now we're using the L, so everything in
here gets executed, meaning this gets printed out. Well, I hope that those are some interesting examples
of if and else statements, how you can use them
and why they are. So actually really,
really awesome. You can see like we already, we almost made a tiny
little game over here just with one if else statements
with a gold, with a toll. And that is really
awesome already, right, for a tiny
recap once again, if and else statements use boolean values to evaluate
something, right? They can use a normal
Boolean value. You can use the relational
and logical operators to chain those
Booleans together. As we have seen
in multiple ways, we can use if and
else if and else statements to chain those
if statements together. And then everything inside of that if statement is executed. If the Boolean
expression is true, really a very cool thing. And I once again, only highly recommend playing around with this a little bit
on your own time. It is really, really awesome. Well that is it for this
lecture right here. I hope you found this useful and you'll
learn something new and I'll see you all
in the next lecture. So, yeah.
9. (Lua) Local Variables: All right, welcome back to the loo introduction here
for the Roblox course. And then this short lecture, we're gonna be talking
about local variables. So for this, once again, in the server script service, let's create a new script
and we're going to call this 06 dash local. And this is of course
also going to have a common O6 local variables. Now, this is not an
insanely important topic. However, I did want to, we'll basically
talk about it once. So local variables before
when we had a variable, we just did x equals, I don't know, like
100 and that was it. Now, we can also put the
keyword local in front of it. And you can see, you can
see that it's a keyword because it gets
bold and also red. So now we can say
local y, e.g. is 50. Now why would this be
important or why not? Well, the general idea is that
a local variable basically makes it so that it restricts
it where it is accessible. Right now in this
case, we actually, it doesn't matter because we
can just do print x and that everything's gonna
be fine and print y and everything's
going to be fine. So both of those are
just going to work. Let's say we have
an if statement and we're just going to say x is, let's say bigger than five, and then we wanna do something. Now, if instead of
that, if someone, let's say this is statement
is really complicated, really complex, and
we actually need some variables inside
of it to function. We could say something like e.g. z equals 100. That works. And we can then use this here
and whatever we wanna do. And the crazy thing
is we can then even use this Z outside
of this if statement. So you can see the Z here is accessible outside of
this if statement, but this is not always what
we want because number one, this can confuse the
person using this, right? So maybe we actually
don't want this. Z is only usable in
this if statement. And after this,
whatever it becomes, whatever value it has is not even representative of
anything that we want. This could be the case. If this is the case, then
e.g. we can make it local. And you can see what
happens is this now has a red underline,
meaning and error. You can see alone global z, because normally variables
are global variables. But in this case, we're
explicitly saying this is a local variable and is only accessible within this
particular context. The context being
the if statement. So if, if it ends
the first n-tier, the end for this if
statement basically also deletes quote-unquote,
this local variable. Overall, it is a normal
thing to basically make everything local except
if there are moments where, oh, you know what, actually
this shouldn't be local. In theory, what you should do is every time you
make a variable, always just start with
a local And that's, and then you're gonna be fine, and then you're gonna be okay. Because there are
very few instances where this is not the case. And you can see if
it isn't right, if you then want to
continue working with this, then it's totally fine, then
you can leave this out. But usually you
want to make them local and then you're
gonna be fine. Another additional reason
why you want to do this is just because they're a
little bit more performance. Now to be fair on
modern machines, this is probably not going to do like a lot of
difference here, but just in case it can
be quite important. And if you see the local on other people's scripts,
then just know, usually you want to
use them for all of your variables
except for in very, in some circumstances where
global ones are needed, then you can keep it out. Usually when I instantiate a variable with local in
front of it, right? So I just made sure
that the prince over here are commented
out because of this print, of course, which throws an error while we have a local variable. But overall in, to
summarize here, once again, local variables, they make a little bit
faster and they restrict the scope where a particular
variable is accessible. Not making a global makes
it a little bit tight, easier for people to
use your scripts. And also it makes the game
just run a little bit faster. Might be miniscule changes here, but usually you want to use
local whenever possible. That's gonna be it for
this lecture right here. I hope you found this useful and you'll
learn something new and I'll see you all
in the next lecture. So, yeah.
10. (Lua) String Operations: Alright, welcome back
to the Roblox course. And in this lecture
we're going to be taking a look at string operations, of course, first of all, in the server script servers, let's create a new
script over here, and let's rename it to 07
and dash string operations. And of course, once again, we're gonna do an 07
string operations, Ahmed over here, and
then let's begin. So we can make a new variable. Let's just call it a
test and we're going to call it something
like hello there, I am saying hello, and that is a string. And we've seen this
previously. We can e.g. print this out with the printf function putting in
tests right here. And that is going to, of course, then output the value of the
test variable in this case. For this, we need
the output over here and also
making sure that in the old ones and
make sure to comment out the print functions in
the old scripts as well. And if we have the
output window open and the print over here, then let's just play and we should be able to
see hello there. I am saying hello, well
that's pretty good. Now why am I writing
something so weird in there? Well, because we're going to see something
interesting in a moment. But the first thing we
can do with a string is figure out how
long the string is. Because maybe sometimes
we want to do that. So we can figure out the length of a string by doing
the following. What we can do is we
can say hashtag test, and that is going to output the length of this
particular string. So it's just going to
count how many characters there are, including spaces. So before we're going
to output this, let's actually count 1,
234-567-8910, 1112, 1314, 1516 1718 1920 201-20-2203, 2420, 5206, 2728, 2930. In theory, this test variable, this string right here, should be three characters long. So our print over here should turn out length
of a string, 30. Let's play and see if
this is indeed IT. And length of a string is 30. Nice. This is already pretty cool, but what other things can we do? Well, there are a whole
host of different things. So let's say we make
a new variable. What we're gonna do is
we're going to type in string and you can see it actually starts
suggesting this to us, and it also marks this as blue. So it is a keyword in this case, and we can put a dot after it. And then you can see we have different functions
that we can call. And those basically represent a certain thing that they
do with certain things. So e.g. here returns the
length of the string. So instead of doing the hashtag, you can also do string that Lynn Wright and then put
the string in there. Very important. So
we can do this. And in this case the new test is actually going
to be the length. Let's just call this
length for a moment. Let's copy this just as a test. And we can then put
in length right here. And if we play this, we're going to see 30.30 because it's basically
doing the exact same thing. But this is one of the
operations that we can do. So usually most of the operations for
strings in this case always proceed with string dot and then sort of
function basically. Let's do a new test
and let's take a look. So string that. And you can see there's
a bunch of stuff. So you can see this concatenates n copies
of the same string. This is basically
just if you have, if I put the string
in there and I put three in there, then
it's gonna be hello there. I'm saying hello. Hello there, I'm saying hello, hello
there, I'm saying hello. So this is basically just
to repeat the same thing. Sup is. This is a substring and this is similar to what we are
going to see in a moment. The description here. It can be a little
bit complicated, but don't worry about it. Byte is usually something
we don't really need. But what I do highly recommend is you can always
take a look at each of these functions and we'll basically just click on
them and then you can see a pretty good
description and you can even click Learn
more to learn more. What we're gonna do here
is we're going to do g sub, g sub. This looks crazy complicated,
but it actually isn't. So let's just
double-click on this. It's going to format all of
this correctly and we're just going to put in
the test string comma. And then this is a pattern. We want to look at this pattern. So e.g. hello. And we want to replace
it with something. And in this case we're
just going to replace it with a normal string. And this string is
just gonna be Howdy. So what do you expect to happen here if we now
output new test, right? So if we were to print
new test, right? So this new variable, what is going to have G sub, hopefully what it's
going to do is going to take the test
variable right here. And it's going to look for
the word hello, right? And it's going to
return a copy in which every time hello comes up, it's going to be replacing
that with Howdy. So if we were to
print out new test, well, hopefully
what we're going to find is it's going to
say, how are you there? I am saying Howdy? Let's play and see if this
is indeed what happens. And this is indeed what happens. How are you there?
I am saying howdy? Now what is extremely
important if I were to also print out the original
test right here, right, because we have put this into the function and we've replaced
the hello with a Howdy, you will find that
test has not changed. So you can see test is
completely unchanged. And this is also what it says. If I just stop here, it
is also what I said. If we go in here, it returns a copy of the string
that has passed in. So it, it does not modify the string that we
have passed in. That's very important
to remember. Another thing I can show you
is e.g. finding something. So this is going to
be string dot find. So this is another method that's actually took a look
at what it says. So looks for the first match of the pattern and then
returns the indices. Okay? So what does that mean? Well, let's just put in e.g. test over here. It doesn't
matter which one we put in. And then I can say there, so we're going to
take a look at there. And then we can also
print this out. So where is we're
gonna do it like this there and then
output finding. And we should get a number
out of this so you can see where is there seven, okay, so why is it at seven? Well, if we count
once again, right, so I'm counting the
characters to my right, So it's gonna be 1234567. So this is indeed the
seventh character, or it is the character with indices or index of seven.
That's the general idea. And then to fund things that you can use if you sometimes, it's interesting and that
is basically shouting case and then whispering case. So the idea is that
string dot upper, and if we put
something in there, and then we can just copy this. So just selected Control C, Control V to paste it in. And this is then whispering
and this is then lower. What you will find
is that the upper, It's just going to see
returns a string with all lowercase characters
change to uppercase, while lower here
returns a copy with all uppercase letters
to lowercase. So if we do this, you can
see shouting hello there, I am saying hello and then
every spring is like. So those are pretty
cool as well. Now these operations,
including some of the other functions for strings, can be incredibly
useful if you have any sort of texts that
you need to modify based on maybe the location
of the player or you need to output
something somewhere. So this can be basically used
for a whole lot of things. That is why it can
be quite important. And of course, as
always, I highly recommend playing around
with this a little bit. There are of course, a few more string functions
that you can use. But in conclusion, you can get the length of a string by
either doing hashtag than the string variable
or you can also use the string functions from string dot and then whatever the function is
in this case Len. We've also seen how
you can replace things in strings and always
remember that this returns a copy of the original
string is never changed. We can even find things and strings and at the
end here we also seen changing lowercase and
uppercase characters as well. Well, I hope you found this useful and you'll
learn something new and I'll see you all
in the next lecture. So, yeah.
11. (Lua) Loops in Lua: Welcome back to the
loo introduction here for the roadblocks cores. And then this lecture
we're gonna be taking a look at loops. Now, what are loops? Well, they are very interesting. First of all, of course, a new script over here, 08 dash loops and a nice comment
at the top here as well. And the question
is, what are loops? Well, well what if
I gave you the task to print out every number 1-100? You could say, well, okay,
let's just start right. We're gonna do one and then
we're going to copy this. I'm going to say 23 and 4.5, and at some point you're done. Now I'm going to
say, well, actually, what I would like you to do is every even number should
actually not be printed. I only want the odd numbers, 1-100 and you're gonna be like, Wow, that's kind of annoying. So you're going to
either a comment out every even number or you're just going to delete
every even number, then I'm like, Oh, sorry, I read this wrong. I actually wanted the
other way around. I actually didn't want to
print out the odd numbers. I actually wanted to not print out the odd
numbers and you're like, Oh my God, I just
changed everything. And at that point you're just
going to be very annoyed. Of course, this is
not the way to do it. There's a far easier
way to do it. That is, loops, basically
loops in a very overview term, or certain pieces of code
or certain pieces of script that are going to
repeat x amount of times, however many times
you basically want. So e.g. we can make a for-loop. You can see this already
suggests you can make a for loop and this already is being
highlighted as a keyword. And the way that this works is I'm going to write this out
and I'm going to explain. So we can say I is equal to
one and I'm going to say ten, and I'm going to say comma again and then one and then do. And as soon as I press
the Enter key right here, you can see that
the end degenerates and everything inside
of this for-loop, similar to what we've seen
if statements, right? Everything instead of this
for loop is going to be done in this case ten times. Now how is this?
How does this work? What does this craziness mean? Well, this means the following. It means that the loop, we need to start
counting of course, because we need to know how
often are we going through. Whatever we put in
here, we can just print out i in this case, right? So we're going to
just print out the number that we're counting. And the question is, okay, we started one
will start at one, meant by this, right? So we're starting at one, okay, that should be fairly
self-explanatory. Started one. Now we're going to end at ten. This is what this number means, and then it's
extremely potent. This number means
that we're increasing the count by one every
time we finished the loop. We could also do three. So then we're increasing the
count by three or two or six or nine or honored
26 if we wanted to, we can do a lot of
stuff with this. But for the time being, we're just going through this. And every time we go
through this print, we're increasing this I by one. And as soon as it reaches
ten, we are done with this. Well, let's play and
see what happens. And you will be able to see if we expand the output
just a little bit. 1 234-567-8910, exactly what
we would have expected. But we're increasing this I by one every time
we finished a loop. So we're starting over here. We're like, Okay, I
is one right now. The rest doesn't concern
us at the moment because I is not ten or
it's smaller than ten. So we're like,
we're totally fine. And then we're printing out
I, which is indeed one. We're getting to the end. So we're going back
to the for-loop. We're like, okay, now
I is increased by one, so now I is two, and so on and so on and
so on until we reach ten. And then the loop is
like, Oh, look at this. I is now ten. So we're done. And that is what's called
a for-loop in this case. Very interesting indeed. Now we can also have a
different type of loop. Let me just stop the
game for a moment. And we can have a
different type of flu and that is a while loop. So e.g. we can have a local variable x over
here, that's three. And then we can say while, and we can say while x is
smaller or equal to ten, then we're going to do something it will have
in series you get an explicit boolean expression
that has to be true. And while this is true, we're going to do
this now while loops are notoriously prone
with the following thing, and that is an infinite loop. Infinite loop happens if, for whatever reason, you
never get to falsify this. So if x is always
smaller or equal to ten, then this while
loop is going go, going to go forever. Now I believe, if I
recall correctly, Lula and in addition, Roblox Studio have sort of a
built-in fail-safe for this, so that your entire
Roblox Studio won't crash if this happens. But I still recommend
you don t try this out because it
is kind of annoying. So inside of here we can e.g. say, okay, we're just
going to increase x by one every time and
then we should be totally fine because of course, if we increase this by one, at some point is going to
be bigger than x, right? So if we can just say print and that's actually
also print out x, y naught would be the case. And let's do it before
we increase it though. So we're going to print out
three all the way until ten. And then we should also
be outside of the loop. So let's just make
another print over here outside the loop. And let's play this and
let's see what happens here. And of course, 3-10, where outside the loop,
absolutely no worries. We can also do, and this
is just an example here. Inside of it. If we're inside of a while loop or a for
loop for that matter. Right? Let's say we want to
be like, Okay, you know what? When x reaches seven, then we actually want to do the following and we're gonna break. Break is another keyword
which is going to completely immediately break
out of the loop as if we have reached
the end of the loop. And that doesn't mean
we reach this end. We're like we're outside of
the little bird jumping out. We can also use continue. And this would act as if we have reached
the end over here. So this will continue the loop. This will break the loop. This will basically
we're outside of the loop at that point.
That is the general idea. So if we use break here, then we're going to have
three to seven output. You can, or in this
case six actually because we're outputting
x before we increase it. So x is six, it gets, it gets
increased to seven. X7, we're breaking out and
that's why we have 345.6. And then we're outside the loop. If we were to do
a continue here, what would happen is actually nothing would be
different than we had before because nothing after this if
statement is relevant. However, if we were to put it at the very beginning over here, now it will be
interesting because now it's seven
wouldn't be output. So if we see this right now, you can see all of a sudden, what would happen is we would
run into an infinite loop. Now this is of course, app. So you can see we've exhausted the allowed execution
time because what happens here is that x is seven
and then we're like, okay, let's continue and
then it's like exercise. Let's continue, Let's continue, Let's continue, Let's
continue, Let's continue. And it's going to do this until, in this case, allowed
execution time is achieved. That is 10 s, if we
can see this right, so the difference
here in time is 10 s. So in theory, this can happen. So this is why you should
be careful with this. So we could e.g. do
something like this. So the print happens
afterwards and then what the increase
here happens before. So if we were to do with this, then all of a sudden we jump 6-8 and we jump over
seven in this case. So that is another
interesting idea. And then also we
have a repeat loop, which is pretty much a very similar thing
to the while loop. What we're basically doing
it the opposite way around. So we're basically saying, Hey, we want to repeat the following code until
something is true. That's pretty much, it's almost equivalent to the while loop, but it's a little bit different. And that is written like this. That is pretty much
everything about loops. Or they can be interesting. That should be pretty much
there is to it, right? In summary, loops are incredibly easy and
efficient way to repeat code that you
want to repeat it x amount of times
there are for loops, while loops and
repeat until loops. And those are the, I think the three main versions. There's also some
interesting stuff for, for loops later that we can
see all four each loops. But overall, those are
basically the big three. And they can be very,
very interesting indeed. So I do highly recommend playing around with
this a little bit. If you want a little
bit of a challenge, this is just a
challenge for yourself. What you can do is
you can increase this to 100 and
print out numbers 1-100 and then do exactly what I told you
to and basically say, Hey, we only want to print out numbers if they are
divisible by two. So if the, if there are
even or if there aren't. So this should be actually fairly straightforward
with the if and else lecture and the loops lecture, you
should be able to do that. I highly recommend
you try this out. It is a very fun exercise. Regardless of that, I hope you found this useful
and you'll learn something new and I'll see
you all in the next lecture. So, yeah.
12. (Lua) Functions in Lua: Alright, welcome
back to the loo or introduction here for
the roadblocks course. And in this lecture, we're going to be taking
a look at functions. So I have set this word
a couple of times. Let's create a new script
over here and rename it to 09 dash functions, and of course also 09
functions right here. Now the question is,
what are functions? Well, as a high, high, high level overview, you can basically put multiple instructions instead of a function and then always execute that function
instead of doing all of these different things as a high-level example, we
can write a function. You can see this is a keyword and then this is the
name of the function. Let's just call this
cooking, right? And then we can even put
something in here so we write the name of this function and
then we have parenthesis. As soon as you put in
the open parenthesis, the closing one should
generate automatically. And here you can then put
in certain arguments. Those are called parameters, are parameters and they can
be passed into the function, thus changing the output. So in our coding example here, Let's just put
nothing in here and actually just actually
just go to the end, press Enter, and
then the end here, we'll once again
generate automatically. This is the same thing
that we've seen with the loops and the if and
else statements as well. And inside of here, if we're cooking something, I can now put different things. Now, in this case, it's
not going to work. I'm just going to do
comments just so that you get the idea of a function. What is a function, right? So every time we want to cook, maybe we actually want to
cook something specific. So let's just say, let's
just say we're going to call this cook dinner for
the sake of argument, right? And every time I
want to cook dinner, There's a few things
I have to do, right? So I have to get out cutlery, I have to maybe
preheat the oven. I have to make a cut
vegetables, things like that. So there are certain
things that I always have to do if I want to do
this specific function, right? This specific thing. And you can list all of
them inside of a function. And then instead of writing
each one individually, if we were to do
this multiple times, we would always have to read
each and every instruction. And that's madness. Basically a function
is a container in which you can put multiple different lines
here in this case, and they will then get executed. Now this is a high-level example
for you to get the idea. Hopefully. Now let's actually take a
look at an actual example. So one actual example
could be a sum function. We are inside of
the parenthesis. We put actually number
one and num two. And now the crazy thing is, if we were to call
this num function, we actually want
something returned. So we can say return. And you can see this is
also a keyword and we want to return num one plus num two. And this is now what
is being returned. Now of course, in this case, we already have sort of some function by just
using the plus operator. However, this is once again, just as an example
for you to start to understand functions and why they can be
extremely useful. Because now what we can do is we can print and we can say, well the sum function, right? And we can just print
some and then say 3.10. And this is, as you can see, this is, we're calling
the sum function. You can even see that it
highlights over here. If I click on this
and inside of here, we can pass in a one number and another number, and
those gets summed here. So these are parameters that
we're passing in parameters, you always have to have the
correct amount of parameters. So if we do, if I
were to do this, then while we're not
getting any issues here, if I actually were to run
this, we would get an issue. But for the sake of argument,
let's just play this. And we will see that if
I look into the output, we attempted to perform
an add on a number of nil because if I don't
pass in something right, then what is passed in is nil. Now we've heard
this before, right? Nil, it was just the absence of any value in a certain variable. So we do have to
pass something in. And if we were to pass in
both numbers over here, then we will be
able to find that the sum function outputs 13, which is exactly what
we would expect here. Now of course, when you're
actually scripting something, functions can get much more
complicated than this, but this is just a very, very tiny introduction
into functions. We will be seeing those
when we're actually doing some programming
with Roblox itself. To summarize over here, functions you can basically
use to batch together multiple different things and have them all executed
one after the other. This can also include
other functions. You can also return to
certain things and functions. E.g. we have a sum function here where we pass
in two parameters. And those are then going to be returned after we are
doing something with them. That is a general
look at functions. If you're not entirely sure
how to use them, don't worry, the most important thing
is that you have been introduced to this
topic and we will be able to see more about functions in later
lectures as well. Otherwise, I hope you found this useful and you learned
something new. I'll see you in
the next lecture. So, yeah.
13. (Lua) Tables in Lua: Alright, welcome back
to the loo introduction here for the robot scores
than this lecture, we're gonna be taking
a look at the tables. Now, tables are a very
interesting thing and they can be
quite complicated, but don't worry at all, we will be fine. So let's do tables over
here and hash tables, and then the same
thing over here. And this is tables are tables. The general idea of
tables is basically that you have sort of a
list of certain things. So when, of course, a table is a little bit
different than a list, but you can, for now think of it as a list and so that we
have something to test. I'm gonna make a local
variable called days. And these days,
this is going to be a list of all the days
from Monday to Friday. First of all, What
we're gonna do is equal to and then
a curly bracket, the closing curly bracket
generates automatically again. And this is going to be a
table of strings in this case. So this is gonna
be Monday comma, and then we have Tuesday. And can you guess what
comes next exactly? Witnesses day, which is how it's written Thursday and
then last but not least, we also have Friday. There you go. So this is basically, well, these are the days and we
can now do the following. We can print, right? And what we can print
is we can print a day. And the day we're going to print is we're going to print well, how about we wanted to print
out, let's say Wednesday. How do we do this? Well, let's think about
this day so we can put in days and you can see
it even suggest this to us. And now how do we actually
get out one of our deaths? Well, we have this bracket over here and insight we
can put in a number. And that number represents the index of one side
of the list, right? So this is gonna be
the element of index one and X2 and X3 and X4 and X5. But everyone, Wednesday, we're
gonna do three and let's just play and see if we get out Wednesday and indeed a day, Wednesday, that is
pretty awesome already. Now, the index here starts
at one instead of zero. So this is only
important if you are already programming and if
you've programmed before, usually when you do other things in other languages and other programming languages, usually indices start at zero. This is not the case in Lua. In Lua, every index starts at one. This
is very important. Now if you don't
know what any of this means, don't
worry about it. That's fine. I'm just saying that for people who have already
programmed before, this is a very, very important
thing to keep in mind. Now of course we
have output one, but what if we maybe want
to, we'll output everything. So this will look a little
bit more complicated, but we have a
for-loop that we can use that will basically output, well, everything inside
of this particular table. Now, there's two different
things that we can do. We can either use a normal for-loop right
where we are like, Hey, I want to start at
one and I want to stop at. This is a very
important hashtag days. So this would be the length
of this particular table. Like how many elements
are in this table? I want to increase by one. For this I wanna do and
then just print days. Once again brackets. I saw this in theory
should output Monday, Tuesday, Wednesday,
Thursday, Friday. That should be totally fine. Let's just see if this works. And of course, Monday, Tuesday, Wednesday,
Thursday, Friday. Absolutely, no worries. And it works totally fine. This pretty cool. There's a second way
that we can do this. This totally works, but there's another way
that we can do this. Now this one, a little
bit more complicated. The reason though
that the other one might be interesting
is because right now the tables are
mapped to the index. So basically this is
red, this is one, this is two, this is three, this is four, this is five. In theory, I could
do anything I want. So I could do, and
I'm just gonna, I'm just gonna do crazy stuff. Let's just say a equal to
this is equal to this, C is equal to this, d is equal to this, and then
F is equal to this. F is E. Actually, there you go. So you can see that
there's no, No, there are no errors
over here because now they're mapped to
different keys, right? So now the crazy
thing is if I were to keep this and I'm playing this, what you will find is
that a day is nil. And also we're not
outputting anything because there's no,
This is all nil. It, this doesn't work. But this well we need
to do is we need to get the key value pair. Because we've
basically transformed this table from a normal
list in which you can access the elements via the
index to a sort of a dictionary or a map which maps one value
to another value. So now we can do a for-loop
with a key and a value, and this is going to be in
pairs of the days table. Then we're gonna do something. But this looks pretty crazy. The general idea, however, is this, this is the new thing. What we're taking is
we're getting a key that is always the first
thing here, right? So a is equal, this is the key and the value is whatever is written
inside of it, right? So before the key was
just the index 1,234.5. And now the key is a, B, C, D, and E. This is the only
thing that changed. And if we were to
do the following, if we now do day or let's
say, let's say key. And then we're going
to print out the key. And I'm going to do the value and then print out the value. What you will find is
that this will output key value Monday and
so on and so forth. But let's just play this. You will see key a value Monday, key C is Wednesday, interestingly
enough, and this is also a very important thing. It is no longer in order. Isn't that crazy? Well, this is indeed the case. So let's just play this again. As we see we had Monday, Wednesday, Tuesday,
Friday, Thursday. Let's do this again and we
get the same order again. This is another extremely
important lesson because if we're using this
pairs right here, the order that we've saved
this in is not guaranteed. That's extremely
important and has to be basically kept in mind. However, it is still a very,
very interesting thing. But do keep this in
mind, it's very cool. And if I were to delete the value of the keys
over here again, right? And we were to go
through this again. What is going to be the key? Well, it is exactly 12345. Now the order is correct because I don't
quote me on this. I'm not 100% sure, but
I'm pretty sure that the keys are sortable
or orderable, right? So 1234, there's a definite
order to those things, then the order is
always going to be the way that you've
basically save them. And that is pretty cool. Indeed. This is not
everything though, because what is
missing in these days? Well, of course, Saturday
and Sunday are missing. So what we can do
is we can actually insert certain values
into this table. We can do table dot and you can see there's a bunch
of things that we can do, we can create, we can
find certain things. We can even see returns
the maximum numeric key. There's crazy stuff. We can move, things, we can sort them,
we can clone them. But for our purposes, what I actually want is I just
want to insert something. And the thing I want to insert is I want to insert into days. So this is the table that
we want to insert into. Then we need to put in the
specific, in this case, what I actually wanna
do is I want to put this into a specific place. So I'm going to put this
into position number six. And then I want to
put in the value. And the value here is Saturday. And what we can do is
we can just copy this. And then in position
seven in this case, I want to put in Sunday. And if we were to
output this now, so once again, I can just
take whatever I like. Actually, let's
just take this one and then we'll just go
delete it from here. That's gonna be okay So that we don't span the output over here. Let's play, and
you will find that now we have a key
six and that is going to return the value
of Saturday and a key seven that is going to
return the value of Sunday. Very interesting indeed. And then one last thing here. Now I know that this has been quite a lot and this is a lot of new things at all at
once. Don't worry at all. We're going to be
able to, you know, you're gonna be able
to navigate through this with ease a
little bit later. However, this, what I
do always recommend as always is just try out a bunch of things
with this. Try out. Having different values in here by having
instead of strings, you can put numbers in here. And by the way, this is also
really interesting thing. You can even put,
you can mix and match different value
of variable types. You can have numbers in here
and so on and so forth. Which is actually
very interesting because this means that you can have a quasi class. Now, this is a little bit
more advanced and once again, something for the
people who have already programmed
in another language. So you can have, so e.g. we can have a person that
has a firstName, e.g. john. And it can have a last name, which is maybe Smith. And then you can even
have an h, right? Which is maybe a 32. And now what I can do is I
can print person, person. And then we want to put
in FirstName, this y. And then we want to
have the person. We can also do person
dot, and this is crazy. We can even do person dot. And you can see all
three different things that we've put into
this particular table. We can output like this. So we can do lastname
and then we can say, is that we can say
Person.new age, years old. Let me zoom out a little
bit. There you go. So person and what? It's going to output the
person's first name. This is the way that
we can write us. We can also access this by this. And we just have is and
then the age, years old. Let's output this LLS play
this and see if this works. And of course, her son John
Smith is 32 years old. Absolutely fricking, awesome. This is really cool and we can of course go a
little bit further. And now this is just, I
just want to mention this. We can even make a
table of tables. This means that in theory, we can have multiple persons and then have a list
of those persons. We're not gonna do
this here because that is absolutely madness. This is way beyond the scope of the Lula
introduction here. I did want to introduce
you to tables. They can be quite complicated. This can be a little
bit complicated. This can be a little
bit complicated. But hopefully I was
able to nudge you into the direction of sort of understanding what's
happening here. Once again, I highly recommend taking the
script over here, which is of course always
available for download. And you can take this
and just try around. Try doing different
things with it, inserting things in
different locations, inserting things laying around
that the person over here. I highly recommend
just doing that and trying to get a feel
for how this works. But once again, to
summarize overall tables, or they can be lists of things that have certain keys
and certain values. If you don't specify the keys, then the keys are just
one through whatever the amount of elements are inside of that table
or list in this case. And you can loop through them with two different for-loops, two different styles
of for-loops. And that is very,
very cool indeed. We can even use the tables to do something sort
of like a class. Now in this case, it
is a person over here that has a first last
name and an age. And we can output this
in two different ways. Well, that's gonna be it for
this lecture right here. I hope you found this useful and you'll
learn something new and I'll see you all
in the next lecture. So, yeah.
14. (Lua) The Math Library in Lua: All right, welcome back
to the loo introduction here for the roadblocks cores. And in this lecture we're
gonna be talking about the math library, right? So let's once again, of course, create our script over here, 11. This is gonna be math liberal. There you go. And this is going to be 11
math, that's gonna be fine. And this is just
going to be a very, very tiny introduction here. But it might be useful. So we've of course done a few
math things already, right? We've added, we've subtracted, we've multiplied, we divided, and we even got the remainder. Pretty freaking crazy things
that we've already done. But with the math library we
can do even crazier things. So if we were to print e.g. minus five, but we're
like, You know what? Actually, I don't
really care about whether or not it's
minus five or plus five. I actually just want the
absolute number for this. Well, we can just
print out math dot. And you can see here
all of the crazy things that we can basically get
with this math library. We can get a random number. We're going to see
that in a moment. We can even get Pi craziness. We can do the exponent,
we get cosine, we can returns an
angle which you give in radians and it
turns it into degrees. We get the logarithm. There are a lot of things, as you can clearly
see that we can do. And this can be extremely useful for doing even more
mathematical things. If you're like, Oh, I don't
need this math stuff. Well, e.g. having things like the sine wave is
actually really useful. Because what you can
do with a sign is e.g. make perfect circles and so you can spoil things in circles. I'm just saying that that
is one of the things that, where this can be
extremely useful. But in this case we
actually want abs, which stands for absolute. So we're getting the absolute
value of minus five, which if we just play
this is of course five, because, well, that's
the absolute value. The absolute value doesn't
care about the sign. It just cares about, well, what is the actual value? There's other things
that we can do. So e.g. we can do a math teal. So this is going
to be the ceiling. You can see it returns
the smallest integer, larger than or equal to x. What does that mean?
Okay, This sounds like, it sounds way crazier
than actually is. If we put in 10.21, It's just going to return,
well, it's going to seal. So it's going to actually
make this an integer, meaning this is going to round upwards to the
next whole number. If we actually do the other one which is going to be floor, this is going to round down. So we can actually put this up, rounds up and this one
rounds down, dual. Keep in mind, this
does not round with the normal
rounding things, right? So we also have round. This one, in this case also runs down because it's
actually looking right. Or the rule right? 0.5 means you round up and everything below
0.5, you round down. But let's just see,
this should be 111010. Uh, see if that is
indeed the case. And of course, 111010. Perfect. And let's stop this and
let's do this again with 0.5 and then it
should be 111011. And of course, 111011, exactly how we got there. They're absolutely perfect. This is exactly how this
works because this is the, let's say, normal
rounding rules. There you go. So that should
hopefully make sense. We can also get the
minimum and the maximum. So this is also, can be
pretty useful in deed. So this is min,
which is basically, it's going to give you
the minimum number. You put in two numbers, right? And it returns a smaller
number given as r Omega. So that should make
a lot of sense. And then of course we can
have two corollary to that, which is the max one, which returns biggest number. You can actually,
I'm pretty sure, put in as many
numbers as you want. Let's just do that. Why not 60? I mean, that wouldn't
change anything one, this in theory should also
work. Let's just see. And indeed it does. The first one is one and
the second one is 515. So this can be
really useful, e.g. maybe you want to get
the highest number for a high score or
something like that, the Min and max functions
can be really useful. But let's also print out pi because white hat and
not power but pi. And then also we can use
the square root math that SQRT is the
square root of 25. So pi is of course
going to be 3.141, 5265, something like that. And then square root
of 25 should be five. Let's see, how far
off was I with pi? 314-15-9265? I think I was right. I think I said 649. I'm not sure, but
that basically is pi. And this is of course with
precision, that is amine. Never going to need this
precision in games anyway, I'm pretty sure that this is the precision that
you're gonna get you, the circumference of the observable universe
within millimeters. So I'm pretty sure
this is gonna be fine. And then of course, the
square root of 25 is five. Perfect Last one leaves. You can also have
some randomness. Now here is very important that randomness for the computer
is always pseudo-random. Basically, this means you
seed it with a certain value. And when you generate
numbers that are always going to be the
same, this is the same. The idea of e.g. when you think about Minecraft world generation as an example, you can put it in
a seed and then it always generates
the same world. Well, how does that work? This is exactly the seed
that you're putting in. And then the values that you
get out are always the same. So we can do a random, this is going to give you
a number, number 0-1. And you can also do
math dot random. And we can actually
put stuff in there. So we can put in a 0.10
and those are going to be the lower and upper
bounds that you can get. So let's just play
this and we can see that the first number is 0.6, whatever, whatever, whatever,
whatever, and then 42. I mean, what a perfect
number over here to get n. If we stop this and
we play this again, where you will find is that, oh, it's exactly the same
numbers because, and this is exactly the thing, because the seed is
the same, right? So we have the same
random seed over here. If I change this, now we're going to get
completely different numbers. So you can see now
we get 0.0, 69.57. So when you put it in the seed, right, if you put
in 100 as well, you should in theory get the exact same
numbers that I got. And that is, that is the idea of this randomness or the
pseudo-randomness. That is pretty cool indeed, usually if you want to
randomize this completely, what do you take is
the like the amount of seconds on your computer or the amount of ticks
on your computer, because that usually is
random enough for a seed. To summarize. Overall, the math
functions are, well, there are plentiful and they can get you a lot of
different things. You can absolute numbers, you can round up and down. You can get minimax, and you can even get some
constants like pi here and even random numbers which end
games are extremely useful. And they can just, they can help you a lot for a
number of different things. It's morning enemies in a certain area
that's a little bit random or giving random
attributes to enemies. All sorts of things.
Really cool indeed, right? But that actually
concludes this lecture and also the entire
lower introduction. Hopefully this was a good
enough introduction for you to get a little bit of
grips on here with Laura. If you are still not feeling very confident in this,
that's totally fine. There's two things that I
can definitely recommend. Number one, if there's certain topics that we've discussed that you're
a little bit shaky on, tried to go through the
lecture again and see if with all of the different
things we've talked about so far in retrospect, they are now a little bit
easier to understand. Number two, what I
highly recommend is just play around with these, with the different topics
that we've gotten. Just play around
a little bit with the math functions over here, play around with tables,
play around with loops, and if and else statements. You can already do a
lot of things with just these 11 things
that we've talked about. Even though it might
not seem like a lot. I'm telling you, these are the
basis in which everything, every game basically is created
with all of these basics. Yes, of course, there's a
lot of other things as well. But these basics, if
you can't use those, then everything
else is irrelevant because you need to know the
basics, the fundamentals. Otherwise, it just
doesn't work well. In regards to this,
we're jumping into roadblocks proper if this has
been useful to you so far, I would really appreciate
a review from you. Otherwise, I'll see you in
the next lecture. So, yeah.
15. (Roblox) Roblox Studio Explained: All right, welcome back
to the Roblox scores. In this lecture, we're
gonna be taking a look at some of the UI of Roblox Studio. Now this is just going to
give you a general overview, will not go into
every single button and what everything does, because that would take a
two-hour video basically. And that is not quite
what I had in mind. I just wanted to
show you each of the different windows over
here and roughly what they do. So either this or maybe without
the output is going to be roughly what you will
see when you open Roblox Studio for the first
time with a custom game, the first thing that I really
want you to do is go to view and add the
output over here, because the output is one of the most important things that we'll use throughout
the entire course, because it basically
allows us to output anything that we
want through scripts. And this is where this is
going to be displayed. Then let's focus on this
big area right here, which is sort of
the camera view. And you can see right
now I'm in select mode. There's also move mode, scale mode, and rotate mode. Let's say in select mode. And if I were to
right-click on this, now I can move around
if I move the camera, but I can zoom in with the
scrolling the mouse wheel. And if I do left-click, I can actually select
certain things. So you can see now there's
a blue border around it, meaning I have
selected this object. This is the general idea. I can also move around with WASD and with E and queue
up, it goes up and down. You can see when I move the
camera on the top right, the cube over here
moves as well, because this is a
three-dimensional space, it is represented
with an x value, a y value, and a z value of this is just a three-dimensional
coordinate system. I can click on the
faces over here and then it's going to
change to that face. So I can go to the
top-down view. And now I have everything
in top-down view. It might be useful
for certain things, but I can also always
rotate out of it. If I select a certain object, you can see it lights up in the Explorer on
the right, right, so you can see the
small location over here is then highlighted. And the general idea is
that I can also just click on this and then it
also gets highlighted. So this idea of the explorer. The explorer
represents everything that is inside of our game, both inside of the game world. The game world is all of
the workspace stuff, right? So if I were to click
on the plus over here, I could add a bunch
of things over here. We're not going to add
anything right now, but I could add an
insane amount of things. This is basically
all that we see. And then there's also
other things, right? So there's a player's
lighting services, some storage stuff. Some things will
go through most of these things during
the lectures as well. But for the time being, the workspace is really the most important
thing that we have. And maybe the server
script service, where we will basically load in all of our scripts
for the time being. Then on the bottom right, when we have selected something, we can see we have
some properties. Properties represent a
certain object, right? So in this case, this
particular spawn location has these particular properties, just like how you
are human, right? And you have a certain name
that would be a property, just as a general idea. And you can see
different types of objects have different
types of properties. So in this case, the
spawn location is of type spawn location
and it has some data. So you can see these are what is its pen orange or does
this name has a size? So this is part of the
transform and has a pivot, it has some certain behavior, it has collisions, it has
some port properties, and so on and so forth. It even has a force
field which is specific to the spawn locations. Same with the teams,
I'm pretty sure. So there's a bunch
of stuff and you can even add more
attributes over here. So very, very interesting. Indeed, properties
are something that we will look at in a
future lecture as well. And then to just give a little bit of an
overview as well. So if we select this and now
we can change to move mode, and now we can move this around. So you can see I
can now move this. I can also scale it. I can see the scales that
basically if we hold Shift, then we scale it evenly. If we hold control and
we scale it in one axis, we can even rotate
it around like this. And if you want this to snap, then you could do this in the rotate in the
move over here, snap to grid, and then now I can only rotate it 45 degrees. I can only move it in
a one-star increments. That is the general
idea right here. Most of this other
stuff we will see throughout the course as well. The transform might still
be some interesting things. So if we select the
spa location again, you can see this is not
the transform on here. We can go into way more detail on how to
do certain things. So you can see, I just have like much finer control
of everything, especially when I size this up. You can see now the
size of the study is actually represented
over here in numbers, which is really awesome. So I can get really, really precise with things
avatar of the current moment. We don't really
need anything here. So this is just to add avatars, in this case, testing, just to test certain
things right here. From here we can play, we can start a local server
with x amount of players. We can even change
the player emulator. It's very interesting. The view is actually
quite important because here we can enable and
disable certain windows. And as you can see, there's
actually quite a few of the asset manager and
we have the toolbox, and we have the object browser, and the script analysis
and the command bar. So there's a bunch
of things here, most of which we actually
don't need right now at all. Most of the interesting stuff is maybe the toolbox is
gonna be interesting. So this is where you
can load certain things from Roblox into
your game, right? So you can add lights,
you can even add some plugins in
this case, right? So you can add plugins. Some of them cost, some Roebuck, some of them do
not. Some of them are free. Do always be wary though, when you add stuff from
other people that they might have malicious code
in their malicious scripts. That does exist. Mostly this is for
things that are free. Do always take a look at how
many reviews they have and also how many positive
reviews that are half, right? So something that's like 91% positive and has like 100 plus reviews, that's
probably gonna be fine. So do keep that in mind
and we can close this. You can add a grid that is
now a force that grid that we can make a two sort of grid
or a 16th note grid as well. This just helps you to
see what is happening. Wireframe rendering
just basically turns off all of the solids, just gives you a
wireframe of everything. This can save some amount of processing power of your
PC is very slow basically. And then here the plug-ins
for the time being, we will not use any plugins
for the lecture series, because usually we can do almost everything that we
need manually or ourselves. However, there are
some pretty freaking cool plug-ins that
are available. But for the time being, we won't be focusing on that, right? And that is a general overview. Like I said, we could go into crazy detail on all sorts of
things for the time being, we're gonna be fine with this. And we will then basically go from here and take
one step at a time. But that's gonna be
it for this lecture right here until next time. So, yeah.
16. (Roblox) Reference a Part: All right, welcome back
to the Roblox basics here for the robotics course. And in this lecture we're
going to be taking a look at parts and how
to reference them. So what are parts while
pores are everything that exists in the
workspace, so to speak. So if we click on
this part right here, you can see we're
creating a new port. We can delete this again. We can also go to the plus on the workspace and we can go
down all the way to port or we can just put in
part and you can see part and then it also creates a new part for us is
we have this port. We can now drag this around
and move this around. And we can do all the things that we've seen so far, right? We can move around and
we can scale this port. We can make this bigger,
we can make this smaller. We can move this about. So there's a lot of things that we can do with this
particular port. And it's gonna be
very interesting indeed now this one
is called port. And what we might want
to do is we might want to reference this inside
of a script, right? So there's a bunch of
ways that we can do this. For the time being. We're going to
create almost all of our scripts instead of the
server script service, which is going to make this a, well, a server script, right? This is only going to be
executed on the server. The differences
between servers and clients will talk
about this a little more in the future years as
a tiny overview in general, the server is basically
what Roblox controls. That's like somewhere
on a server, somewhere on Roblox land, that you have nothing
to do with that. You are the client, so
your PC is the client. When you connect to a game, you connect to one
of those servers and your client obviously can't
do everything, right? So the client can change the number of
coins that you have. Because if you were
to able to do that, you could just like
press a button or make a custom script
and you're like, Oh, I have 1,000 coins and then the servers
like yeah, absolutely. You have 1,000 coins.
So there has to be a decoupling
regardless of that, right now, sort of
a script service. We're going to create a new
script, m going to call this. We're going to pick
on this F2 O2 dash, and we'll call this
the reference. Ligo will zoom into this once
again and we will call this are referencing a
part in workspace. This is going to be very
interesting indeed. So there's a couple of
things that we can do. So let's say we want to
reference the base plate. We can do this. Let's just make a local
variable base plate and that is equal to game. So we always want to start
with game lowercase. Very important that,
and now you can see I'm getting everything
that is instead of here. So basically game is the
root of the explorer. You can see I get players, which is this guy over here. I get workspace with this guy. And there's a bunch
of other things now, I wonder if you
have a workspace. Once again, very important. The casing is important here. Always keep that in
mind. Workspace with a lowercase w might look like it might work,
but it will not work. So keep that in mind. Always make sure the
casing is correct. That and now all of a sudden, you can see there's
a bunch of things, but there's also camera,
which is right here. And there's part one. Look at this. This is cool part, is this
the same port? Indeed it is. And the name here has
to match exactly. If I rename this,
if I click on this, press F2 and rename this
to port lowercase p. This will no longer work. Now, you can even see, it suggests to us a
port with lowercase because that is the name of the part that
we're referencing. It has to match exactly. I know that I'm
harping on this point, but it is extremely important because I've seen
this time and time again that people have
just changed the casing. The casing is important. Okay, So now we're referencing the part with
lowercase p, right? Okay, that's fine. As a base plate, that's
not what we want. We actually want to
reference the base plates. So basically, there you go. I can autocomplete
this with tab. Now I've referenced
the base plate. I can do things with it. Well, okay. But what about my part
that I want to reference? Well, we're going
to say local again. And then let's call it my part as is just the name
of the variable, which is different from the name of the object of the part. This is also very important. This is what is represented. Insert the code while this is the actual physical object part. And once again, we're going
to say game workspace and then port, not parent. Actually, we want to
park. There you go. And now we can do things
with a port because the part has different
types of properties. We can change those properties
from inside the script. So we can say my part, which is the variable pointing
to this particular part. That, and now you can see
I can change the position, I can change the name, the rotation, the color. In our case, we're
just going to change the transparency to 0.5. And then we'll also do
my part dot dot color. And then we can change this
to a color three dot nu. And then we'll just do
something like while we can actually just change
the color right here. So let's just pick
like a nice blue. Yeah, that's nice. So this is just automatically
generating those colors. You can see if I click
onto the height of this, if I click on Saturday, as you can see, the
color right here, and you can click on the color
wheel to change the color, which is very, very cool indeed. Now what is going to happen when we actually start the game? Well, Let's just go
into the game view. We overhear the port right now it looks completely normal, but if I start the game, this should be transparent
by 50 per cent. So it should be 50% transparent
and it should turn blue. Let's just play the game and let's see where
instead of the game. And if I go around here, you can see it is
now a little bit transparent and it is blue, exactly what we wanted. If we go into the workspace, we can even see the
part over here. It now has a different color
and the transparency is 0.5. Pretty cool indeed, I can see when we're no longer
playing the game, it basically resets to its original properties
in this case, because changing them
instead of the script, it doesn't change
them permanently. So that would be one
way of referencing a part in a workspace
via the name over here. Now once again, it is
extremely important that if I change the
names here to e.g. my cool part right? Now, if I were to play this now, what would you think happens? Well, we're referencing
something that's called part. Let's just play. And we will see that part is not a valid member of works or does not develop
member of workspace. Workspace and it has not changed its color nor its transparency because now the part is called Mike cool part.
So keep that in mind. If you get this
error right here, it simply means
that you probably are referencing something
that has a name changed. If we make sure that we're
doing this, all of a sudden, if we play this, now we can see we're not
getting any errors. And once again, we get our
blue part that is transparent. Pretty cool indeed,
right, to summarize, as I've said, makes sure to
name the things correctly. You can use game
dot workspace dot, whatever the name of your port is that you want to reference. Make sure that these make sure that the casing is
always correct. And then you can access the properties by doing
your part variable dot. And then you can
access all sorts of properties that are part
of this particular part. And you can change
them with a script, but that's gonna be it for
this lecture right here. Hope you found this useful and the alerts and the new one, I'll see you all in
the next lecture. So, yeah.
17. (Roblox) Types of Scripts: Let's continue with
the roadblocks basics here follow Roblox course and in this lecture we're
gonna be taking a look at the different
types of scripts. So we have previously
seen this already when we make a new script in the
server script service, it is basically frequently use says Script and module script. There is, however,
another type of script. If we just type this in here, you're going to see that
there also is a local script. Normal script sadly, apparently
does not have a tool tip, however, the local script does. So you can see a local script is a script that runs on the
client and not on the servers. So the logo scripts can be placed under the
following things. A player's backpack,
player's character model, a use the GUI, the
player script, and the replicated
first service, the module script, right, is a script fragment
and it only runs when other scripts use
the Requires on it. So that's an interesting one. And the script, well, that's
just a normal script. So far we've been using normal scripts under the
server script service. And this then has been run both on the server
and the client. That's the general idea. Now there are some
things that you only want on the
client to happen. Those are mainly things that are basically client's specific. So maybe visuals, right? Maybe you want to add
visuals to a certain client. That's pretty much something
you wanna do on the client. Local scripts or client scripts. They can communicate with a server through
a remote events. But that is a very more
like intermediate, advanced topic that we'll
not talk about right now. But the general
idea is that yes, we can have local scripts. So if we were to, once again, take a look
at where we can add this, a backpack, a character model, a GYE, a player scripts will
replicate first service. So what we can do is we can add this to the
replicated first. You can see it even
says, Hey, local script. And if we were to do this,
and we will just say print, print, Hello, World is
actually totally fine. Let's rename this and I'll say O3 local script in this case. And then just a local script
example in this case, we're just going to
print out hello world, and we're going to
see if we play this, it is going to be output. But now, and this
is a crucial thing. We now get client over here. So this is what we did
not have before, right? We now actually get something
output from the client. And this is extremely important if we were to just go into the referencing one
over here and we're to make a print HelloWorld, just the same thing, just for the sake of argument
and we play this. You're going to see that is now on the server. You
can see there you go. So HelloWorld is
on the server from O2 referencing line
eight and the other one, right, the HelloWorld,
this one is from the client or three
local script to write. Now you might say, well, what's the freaking
difference, right? There's nothing crazy going on. Well, right now this
is my client and I can actually switch to the
server and the server. The server basically
controls everything, right? So the server in theory, I could just say, Hey,
you know what, no, I'm going to move my guy over here and I'm just
going to move him. Now, you can move yourself by
the normal movement rules. But if you were to try and change your position
from the client, only, that that doesn't
work because that would be that's where anti
cheating stuff comes in. So client-server separation
is very important. So that is basically
the general idea with a local script comes in. And like I said, you can
communicate with the server, but that's something for
a intermediate level. And then a module script is
a little more complicated. So we're just going to
make a module script O3 test module here. In this case, let's actually call this testimonial.
There you go. So in the module script,
the general idea is to put functions or certain, basically functions that you're going to use a lot
of times, right? So different multipliers,
different bonus functions, some calculations that
you might be using. A lot of times what you can use is you can make
a new function. And the way to do
it is we're gonna take this table over here. I'm going to say module. So this is the name of
the table that sum. So this is going
to be the name of the method and then
whatever we want. So basically we're just
gonna make a sum method again and we're going
to return this case, not repeat, we're going
to return x plus y. So once again, this
is just an example. Write a sum method. You really wouldn't make a
custom module script for it, but just so that you see, okay, this is how you would
make a method in a module script and then
reference it later. So if we have this, we can now in the server script, servers once again make a
normal script and we'll call this 03 dash testing modules. Why not? That's okay. There you go. And what we're
gonna do is we need to now somehow connect
this module script to this particular script. The way to do it is we need to use the require
method over here, but we actually want to do
is make a local variable. So let's just call
this the summation. Sure, and this is equal
to the required method. And then we need to
reference the module script. So this is game dot
server script service and then.o3 tests module
exactly like that. And then it actually
will represent it like this because we can start a reference of a dot with a number,
but that's fine. We can use it like
this, That's okay. And then we can say,
let's print this out. So let's print
summation dot and you can see it now even
tells us, hey sum, we can use this press Tab
to auto-complete and we can say 50.23 shirt. Why not? So this would be 73 that we're printing out here. So let's play. And we're going to
see that the server prints out 73 right here. Pretty awesome indeed. And of course this is once
again, just an example. The idea here is that you know, if you have certain, if you have certain
numbers, right? So you could add things like a, you know, you could
add different tables. You could add maybe there's
like an experience, experience multiplier or
something like that, right? And then you could just add a new table and you'd
be like, you know, maybe easy, you get
more experience, right? So then you get like 25 points. More experienced,
medium, you get like a normal experience. And then on hard maybe
you get less experience. This is just once again, like just an example of what
you could use here. Now, this one would not only
be available in the module, this is extremely
important because now it's a local
variable, right? Let's just take a look. If we were to print out the summation R and we
would try to use this. We wouldn't be able to do that. We only use some over here,
which is interesting. Now, if we were to do not
local, what would happen now? Do you think that we will
now be able to use this? Well, let's just
take a look, right, summation that we still
are not able to use this, because to use this, we will need to do module dot. And now all of a
sudden it's sort of added to this
particular a table. And now if we go in here,
all of a sudden we have, we have the experience
multiplier available to us that is really awesome
and it can basically, I mean, it just makes
so much sense, right? You could store all a lot of
things instead of modules, scripts that you're
going to use in, well, in all different scripts. Maybe a special
player names that maybe certain things for connecting to certain
services later down the line. So a module script extremely, extremely useful for
a lot of things. And just to show
you, you can see summation experience,
multiplier medium. If you were to print this out, then we would get a one
or here because that is exactly the medium that
we've defined right here. Now that is pretty
awesome indeed. So to summarize, there are three types of different scripts that are local scripts that
run only on the client. Then there are
normal scripts that can run both on the
server and the client, and they sort of
synchronous automatically. And then there are also modules, scripts which are used
to store variables or functions that you will be able to use anywhere
in your code. And that basically helps
you to not repeat yourself. Anyway, I hope you found this useful and you'll
learn something new and I'll see you all
in the next lecture. So, yeah.
18. (Roblox) Properties Overview: Let's continue with the
roadblocks beginner portion of the roadblocks course. And in this lecture
we're going to be taking a look at the properties. So we're going to make a deep
dive into the properties. So let's just expand this
window and let's just take our cool part and take a look at all the crazy
different properties that we have available. So the first one is the
brick color in general, the brick color and the color, or almost the same thing. So if we choose a different
brick color here, let's say like a dark blue, you can see that the
color here changes. And the general idea of
bricolage just they are predefined colors
that are easy to use. While the color can be like
literally any color, right? If I just choose a
random color over here, it's not going
to have a name. So you can see it does say it's like brown, yellowish green. So it's going to
approximate to this one, but it is not exactly
that color, right? So you can see this
one is all love. And then I don't know
this one is olivine, but if I were to change the
numbers here a little bit, right, It's not going to change too much in its
appearance, right? Maybe this is going to
be like a two over here. And then it's gonna
be a sand violet. But you can see that it's, it's not exactly in here. It is just similar to
where's the sand, violet. I have no idea. I can't find it. Well anyway, that's the
general idea, right? So you can put a number here. So this would be a hex, right? Something like that. So
now it's black metallic, but that is not really
black mentality. You can see this
color and this color, they are not the same. So it is the general
idea of the brick color and the color when it
comes to casting shadows, that should be fairly
self-explanatory. Right now casts a shadow
and now it does not. That's, that's pretty
much all there is to it, the material. So you can choose different
types of material. So certain materials have
certain properties to them. So you can choose metal e.g. which is gonna be a little
bit reflective light. So you can see this now really does look a lot like metal. Plastic was just
going to be nothing. So if we choose glass, right, it is not 100% translucent because of course the
transparency is not there. But if we were to make
this transparent, now it would have like a glass Shine n would be
transparent as well. Pretty cool. And so there are a bunch of different materials
that you can choose. Plastic is just the normal one with no real texture
to it, right? So the material
variant in this case, we do not have any material
variance and I'm actually not even sure which one of
the materials does have one. We can go to the
material manager up here and we can actually
take a look at all of the materials that are, that exists over here. Force field, e.g. we could
choose the force field. So this is how the force
field would look like. And then we can go in
here and we can choose the force field,
e.g. force field. And now this is a force-field. So you can see it's very
see-through from all sides. So that's interesting indeed. And there's a bunch
of other things. We've got metal over here, different types of metal,
diamond plate foil, corrodes. Metal is really awesome that you can just with some of
this stuff, right? If we chose corrode metal e.g. if they can see the
color here changes what changes in the
texture itself, right? So now you can see
like the color here is like the base color. If we were to choose this red, then all of a
sudden it gets red, green, stuff like that. So it is really cool what
you can like change here, and it's really awesome. So highly recommend playing
around with this a little bit and getting a feel
for this brick is also pretty cool and you get a brick texture
just on top of it. Pretty awesome indeed, red
reflectance and transparency. We've talked about
this before, right? Reflectance just basically makes the actual thing more reflected. Now you can see that
this is dependent on the material because
now the brick material, they actually cannot
be reflected. If we were to change
back to plastic, which can be basically
anything that you want, we can make this as
reflected as you want. 100% would literally be, it reflects all light. So now it has a, now it's a mirror, right? And that's perfectly
reflecting this. But because our script makes the transparency 0.5, we
actually don't want that. And now we have a mirror again. Now you can see it does
not mirror the player. That will be way too intensive for a lot of the processing. But that is the general idea for the reflectance and
then transparency. We've seen this
already, basically how transparent at this
particular part is. So archival, a very important thing about all of
the different properties. And this is actually
very important. You can hover over this and
it is going to give you a short description of what
this particular thing does. So you can see archival
basically it's just like, Is this going to be saved here? Then we have a
class name that is locked usually because in
this case this is a port. We can also make this locked. Then if we make this lock, then we can actually
move it anymore. So if we lock this
and now I can't even like I can't even try
to select this anymore. And now I can go back in
here and I can unlock it, and now I can select it
again, I can move it again. Very interesting.
Indeed, the name here and the parent should be
fairly self-explanatory. And then these ones are
usually also non-changeable. However, the size is changeable, so maybe we want to size it up, maybe do 758, maybe
something that's not too. There you go. So that's pretty cool. So you can see that now it is sized up and we can also
change the position. So when we change the position, you can see the position on both the origin as well
as the C frame changes. So you can do this
manually as well. So I could do -25.20 again, and you can see now it moved
and that is pretty cool. Now the origin
point is basically, you can hover over this, right? This contains the
information of the position and the matrix of the rotation. You can change this and
you can read from it. The origin, if you
ever though this, this is basically where
this rotates around. So the general idea
is if I rotate it, it rotates around
a certain point in space and you
can see it points, it rotates around
the exact middle of this particular part, right? However, if I were to change
the position of the origin, Let's just take control Z to make the rotation zero again, if I were to change this
to 000 right here, right? Now, the thing actually comes with it. That's
not what we want. We want to offset
the pivot, right? So now if we were
to offset the pivot by 20 minus five and -20, that will be what we
want to offset it by. All of a sudden, the
pivot is at zeros, zeros. So you can see now the position is 00 because
we've offset the pivot. And if I were to rotate, we would now rotate around
this particular position. So now we rotate around this. So that's pretty cool actually, because what you can do
is you can offset it. And if you would e.g. want to have a spinning
platform, well, they can just change the, change the rotation
here and now you all of a sudden you have
a spinning platform. You can go crazy
like a distances. But yeah, that is
really cool and can be used for a lot of
different things. In this case, can
collide and can touch should be fairly
self-explanatory, right? It's just whether or not a physical interaction can
happen in here, can touch. Basically if the Touched
event is called on this, there's also
different collisions groups that you can define. An anchored means
that it doesn't, that is not affected by gravity. So if we were to have this, Let's go and put this up in the air and it's not anchored. If we play, it's going to
fall down onto the ground. So we can actually see this. So you can see it's
now on the ground, even though we put
it up in the air. And if we were to
anchor this right, if we go down over
here and anchor this, then is going to mean that
it's going to stay at that particular position and
not be affected by gravity. So you can see now
it is in the air. Pretty cool, right? Custom physical properties,
massless, things like that. Usually I recommend
staying a little bit away from those because then you
get into crazy stuff, right? The custom physical
properties you can see, you can change the friction, the elasticity, the density. So there are some cool things
that you can do with it. But this is definitely
a little more for intermediate and
advanced users, right? And the rest with I wouldn't mess with for the time being. However, you could always hover over things and take a look at what the different
properties basically mean. And now those are, of course, properties that are specific to a part depending on what
you're creating here. If we click create
a texture or D cow, or a dialogue rate or
a proximity prompt. All of those crazy
things, those are all going to have
different properties. However, you must think, simply realize that a
property is nothing else like a variable or an attribute attached
to a certain object. In this case, it shouldn't
really be anything crazy. But if you have a
property, it's something like spawn rate, e.g. could be a custom
property as well. And then you would be like, oh, that's probably a number that
has a certain relationship to A's to the spawn rate
of a certain thing, right? So this is the properties
overview can be really useful and really cool to play around
with this a little bit. And then you will see that there's a lot of things that you can do with properties and
even custom properties, which we'll see later down
the line to summarize, every one of your objects
that exists has properties. Some of them are properties that all of the
different things share. Like if this is a thing
instead of 3D space, it always has a C
frame and an origin, meaning and a size. So this is basically the
transform signifying the actual position of
the object in 3D space. And there's other
things like collisions, things that are
descending from part can also be anchored massless,
all sorts of things. So there's a bunch of
properties that exist. I highly recommend playing
around with this a little bit, just adding a new port, playing around with some of the properties that exist here. And you can even add your own attributes for the time being. We won't venture
into that just now. But suffice to say
with properties, you could do a lot
of cool things. Alright, that's gonna be it
for this lecture right here, or we found this useful
and learned something new. I'll see you all in the
next lecture. So, yeah.
19. (Roblox) Vector3 and Position: All right, Welcome to the Roblox basics for the Roblox course. And in this lecture we're
gonna be talking about vectors and changing the
position of a part. So we talked about
referencing parts before. We have talked about modules, scripts, and we've talked
about the properties. And now let's actually change those properties properly
inside of a script. So let's make a new
script over here. It needs server script service. Let's call it 05 dash positions. And then let's see. So we'll call this the
vector three and positions. Comment over here and then we will talk
about what that is. So first of all, let's
actually get our part. So that is going to be, my part over here is going to be equal to game workspace, my cool part. So we've seen this previously
in the referencing lecture. So that shouldn't
be anything crazy. And now what we can do my part and now we can
change what I mean pretty much all of the different properties
that are in there, including some some things that are like a lightning bolt here. And we even have these weird like file cabinet type things. For the time being,
we're only going to use the blue cubes and e.g. the position you can see this
is of type vector three, and this describes the position of this part inside
of the world. Currently, if we
just do this and we just print this out just
for the sake of argument. Let's just print this out. We should get a vector
and that is -21.8 and so on and so forth to
0.4, 99.1, 17.93. So that is basically
this position. And if I were to change it, nothing's going to change in the output because we're
only outputting at once. So if I go into the position
here and I will do 50, 50, 50, like the actual
position will change. So now it's over there. But it wouldn't update the output because
while this was already output and we're only outputting it once, that's fair enough. What if we were to change
this position, right? So what if we output
the position and then we're saying y part
that position, and then we want to change this. How do we change this? Well, we change
this by giving it a new vector three, right? So we want to say
vector three dot menu. And then here we
put an X number, a number, and a Z number. Now the important
thing here is that a vector three, write a vector. Maybe you've had
this in mathematics. Maybe you've had this
in mathematics overall. It is very easy to understand. What do you probably
have seen before is, let's do something like this. So you probably have seen
a two-dimensional grid before with a y-axis
and an x-axis, right? And on that, you can describe every single point
with two numbers. Now it's the same thing
in three directions, just as another
direction, right? So this position, like
we've seen before, is let's just make this
a little bit nicer. 2015 and -17 for the
sake of argument, right? So now it's over here
and we can now change this position by just giving
it different coordinates. So let's say instead of -21, we're going to have, let's
do 50, 50, 50 again. And this is now
anchored the parts, so it's going to
stay in the air. So what we would expect to
find is this outputs -20, 15, -17, then we're going to change
the position to 50, 50, 50. So when we actually
load into the game, even though this outputs
the old numbers, this is now changed
to 50, 50, 50. And we can confirm this, we're just going
down and we can see position is 50, 50, 50. Very interesting indeed, but
we can only change that. We can of course change, I mean, pretty much all of it. We can even change the rotation, which also is a vector three. Now, there's some
interesting stuff concerning the rotation in
three-dimensional space. For the time being, we're just going to do the
vector over here. So e.g. we could
do 4500, lets say, and now it should
in the x-direction, we rotated by 45 degrees. So let's just take a
look and we can see, if we take a look at this,
you can see it is now rotated around 45 degrees. And if we actually
take a look at this, you can also see that
the orientation now is not quite 45,
but pretty much 45. There are sometimes
rounding issues. So do keep that in mind that sometimes the rounding
can be a little bit weird with especially
these vectors because there's a lot of calculations that
have to be done. So they sometimes round down or round up in a little
bit of a weird way. We can also do something
that's very interesting and that is maybe we want to
move the part, right? So maybe we want to actually
say, You know what? I actually want the
position to change. So I want to take
the actual position of my part and I just wanted to maybe move down by
a couple of studies. So let's say make a
new vector over here. We don't want move the x-axis. We do want to move it maybe
25 down on the z-axis. And maybe we want to
do a plus five on the, actually not a plus five,
just a 5-year on the z-axis. You can see this all works
because if you do a vector, vector minus a vector, that all works out totally fine. So if we just play this,
we're now going to see that the cube has moved
where it has moved. Well, it is worth,
it is right there. And if we take a look
at this micro apart, it is now in 50, 75, 45. Now you're like,
that's kinda weird. Yeah, that's kinda weird.
How did this happen? Well, we subtracted
this vector, right? So we take 50 minus
zero, that's 50. Fair enough. We did 50 minus -25. Oh, well minus, minus, that's a plus,
meaning there's a 75. And then here we
subtracted five. So that's an interesting
one where if we subtract something that we actually don't want any negative
numbers in here. And then if we were
to run this again, now you can see each will be
lower down and there it is. So it's now a way lower down. And now our calculations
to work totally fine. So that is the general idea of the vectors calculate, right? So it basically is
always the first element minus or plus rate, e.g. that will work. So we would do if
we keep the minus, that will be the first element. The new elements will
be 50 minus zero. And then the second
one would be 50 -25, and then the last one
would be 50 minus five. That is the general
idea of this. What happens if we were to say, You know what, let's times this. Is this going to work?
Well, let's just do 22.2 over here. And let's just see what happens. So there's no errors. And if we take a look, it
is now very, very far away. And if you take a look at this, you can see 150, 90. So exactly what we would
expect here to happen. The same idea, right? Instead of doing a minus, we now do times two. And then we do this basically
for all of them, right? So we do this, and
then we do this. Now this is actually
45 and this was 25. And that is why we get 150.90
as the parts over here. Very interesting indeed. Now there's a couple
of other things that are interesting and that is e.g. if we want to size
something up, right? So we have the size over here. We can e.g. do a
times equals and then we can size it up
by 50 per cent extra. That's going to just multiply or size numbers by 1.5
here in this case. So if we look at this again, you can see this is
now bigger now it doesn't really look
like it that much. But if we go here and see the size is now
10.57 point 5.12. And if we're not running, the size is only 75.8. But those are some
of the examples here of changing the position, the rotation, the size. This is really cool
already, right? In summary, position or rotation is represented
by a vector. And a vector is simply
three numbers here, having an x and y
and the z value. And you can change them with the normal operations, right? Multiplying, subtracting
all of that work. So that is pretty cool
and you do it like this. Well, that's it for this
lecture right here. Hope you found this useful and
you'll learn something new and I'll see you all
in the next lecture. So, yeah.
20. (Roblox) The Wait-Function: All right, let's continue the robotics basics here
for the robust course. In this lecture, we're
gonna be talking about the weight function. So the weight function is an incredibly important
thing that you will encounter many a times throughout scripting and Roblox. And let's just create a
new script over here, call it 06 dash waiting. And we'll just call this the weight function because it is about the weight function. Let's say I have a for-loop. I started at zero and I go to
ten and I increment by one. Let's do this. And let's
say I print out the number. So if we were to do this, it will print out
the numbers right? Immediately. You can see zero all the
way to ten in a matter of, I mean, literally
almost all of them, even in the same tick, like the same milliseconds. That's how fast it was. But let's say No,
no, no, no, no. I want this to print
out every second. Well, we'll just use the
weight function over here. I'll pass in one. So what it actually does is it yields the
current thread until the specified amount of
time is elapsed in seconds. Now it's very important
is that this can have, let's say like
negative consequences if there's a lot of
scripts going on. So the weight function
isn't a end-all, be-all that you should
use it everywhere. There are other ways of sort of waiting for things
to happen as well. So this isn't the
be-all end-all. But in this case, if
we were to run this 012 and you can see
it keeps going. It keeps I can run
around, it's all fine. And it keeps going
exactly 1 s after another and our attend and now
the weight is done. So that is pretty cool. This is cool for certain things like for counting
things, stuff like that. That's really awesome. This is an example of where the weight function
could be really useful. It's sometimes also it
can be important if you're importing certain things and sometimes you're just like, I'll just wait for
a little bit and then you can continue
executing something. But like I said, the actual thing that it does is it basically yields
the current thread. Now this is high
level of computer speak basically for
saying that it's sort of stops
everything that it's doing in this particular sort of workload and then continues it after the
seconds have elapsed. So there are things
that when you use this, it could possibly break
certain things in your game. So do be cautious and not
use your weights everywhere. We're just like, oh,
this doesn't work. Let's just put in
a wait over here that that's usually not
what you want to do. I just want to emphasize
this one more time. What I'm going to comment out the print and that is pretty much all there is to
the weight function. There really isn't
anything to summarize. It just waits for a
couple of seconds and you shouldn't use it
everywhere in your scripts. There's gonna be some examples of where we're going to use it, which are going to
be interesting. And then there are some
examples where we could use it, but we might want to
use something else. Well, that's gonna be it for
this lecture right here, or we found this useful and
you'll learn something new and I'll see you all
in the next lecture.
21. (Roblox) Basic Part Movement: All right, welcome back
to the robotics basics here for the Roblox course. And in this lecture
we're gonna be looking at moving a part. So this is gonna be very
interesting indeed. So for this in the server
scripts service, once again, making a new script and
we'll call this 07, and we'll call this movement. So this is going to basically take in some of the things
that we've learned so far. Of course, to move apart, there are plenty
of ways to do it. By the way, this is just
one example that we can use with a current
understanding that we have. So there are different ways that we would be better
even to move parts, but it is possible
to do it this way. So I just want to emphasize this is not the only way and it might not be the correct way for every certain thing
that you wanna do. But we're just going to
take a look at this. So basically, let's just
get our cool part here. Organ, let's say local my part. And we'll say, this is game
workspace dot my cool part. There you go. Then what we'll do is
we'll make a for-loop. Once again, we're going
to start this at one. We're going to then go to, let's say 15 and we
will increase by one. And what we'll then do is inside of that for loop
will say my part, that position is now
going to be equal to my part that position. So the actual position that
is at plus a new vector. So they're going to
be vector three new. And then we'll just say,
let's do IO over here, 0.0. So we're setting the current
position to itself plus I. So we're starting with one. And then if we were to
do this and we'd start, we just basically get position
plus 15 because that's it. But what if we now wait a second in-between this,
what would happen then? Well, let's just take a look. Let's stop this. And if we then find our
part and we run towards it, you can see, oh, look at this. It is moving one step at a second because it's
waiting 1 s and then increasing and then waiting 1 s in increasing and
waiting 1 s and increasing all the way until it has reached its
final destination, which would be plus 15 in the x-direction. And
we can see this. So now its position is 220, so it should have been 205
before because of the, all of the recruits, the
things that we've been doing before with the scripts. So that is the general idea. So you can use the wait
function in this case to delay the setting of
the position and this, and thus it makes it look like it's actually
doing something. So you could e.g. also do, you could also do
this, maybe 50 and then maybe you put it
add a little bit less. So maybe like a
quarter of a second. And if you were to
look at this now, it will look much smoother. So if we look at this, you can see now it's
not like smooth, but it's almost smooth
movement, right? And we could do
this even smoother. Now I have to increase this because of course
it's going to move faster if I increase this or
if I decrease the wait time. And if I were to look
at it like that, now, you can see it's
almost a smooth. So to summarize, while this is one possible way of doing it, we will actually see some other ways in
future lectures as well. This is because there
are some things that we need to cover
before we actually do this. Because there's just a few more interesting
things that are, well that needs to be added
to your toolkit, so to speak. But for the time being, that was it for this lecture right here. Hope you found this useful and you've learned
something new. I'll see you all in the
next lecture. So, yeah.
22. (Roblox) The Touched Event: All right, welcome
back to the Roblox basics here for
the robust course. And in this lecture
we're gonna be talking about the Touched event. Now we've seen a lot
of things that we can change in the code
and in the scripts. However, we have
not really gotten to any part where we
can actually sort of inputs something
or we can make something happen while
this is about to change, Let's create a new script over here in the
server script service. We're going to call
this 08 touched event. And this is going to be
very interesting indeed. So the Touched
event is an event, as the name suggests. And events are basically, well things that happen. These are, these
are events that can trigger certain functions
to then get executed. In the Touched event
is basically called every time that a part
touches another part. So let's just for the
sake of argument, actually get rid of all my
positioning changes here. Because we actually
don't want those two. Well, we will don't
want this to affect the R core part here anymore. So let's just play this and then our cool part should
just stay where it is. Well, it's going to zoom off, but that's actually kinda funny. So that because of
the movement here. So let's get rid of
our movement as well. And now we should
have a clean slate. So for the Touched event, first of all, we're going
to get our part again. So my part is once
again, game workspace. And then my cool part in
this case, there you go. And then we're going to
have a touched events. So we're gonna say my part dot and then we can say touched. And you can see this
is a lightening bolt. So a lightning bolt, that is a, an event. So you can see
this is fired when a part comes in contact with
another part. Very cool. You can also take a look at all of the other
lightening bolts. There's also a
change, one right, fired immediately after a
property of an object changed. Could be interesting
that we want to see this destroying
fires immediately before an instance is destroyed. Okay, touch ended is when you stop touching another part,
and so on and so forth. Now we want to use the
Touched event over here. And then we wanna
do is we wanna do a colon and then connect. This is very interesting. So you can also do
some other things. You can also do once this would
then call something once. This one connects a function to an event, basically saying, Hey, is this particular
event is called, then we want to actually
call this function where there's also a weight
which waits for something. And then here connect parallel
is even more complicated, basically once and connect
are the interesting things. So let's say we say
one's right in here, inside of this
particular function, the ones function, we can
put another function, right? And then we say other part, and we're just going to make this function
instead of this one. So you can see this is
the function right here, and this is the closing
parentheses of the once. And then we can just say print, and then we can say
e.g. other part, right? So what happens here is that this other part is the part
that it has touched my part. So if we were to just play this particular thing,
what will happen? Base plate, you
might be like what? Well, look at this. The micro part is touching
the base plate, right? And if I were to jump on
here, nothing would happen. Why is that? Well,
because once means once, it happens one time. And then I said, however, if we were to
connect this, right, if we were to say connect,
what would happen now? Well, let's just play this and
you will see It's going to spam base plate over here until it will no longer
span base plate. Okay, interesting
what happens if I now were to jump onto this? Well, let's just do it. And you can see
humanoid root part, left foot, right foot. And also the questions,
why does it stop? Well, the Touched
event basically, you need to start touching and not like continuously touching. That is something a
little bit different. But you can see that now
depending on like a moving it, it gets like different
parts of my body. Because if we go into the
workspace count and Joe, I'm actually represented by a whole host of different
like tiny parts. The left foot, the left hand,
and so on and so forth. And not like my entire
body so to speak. Okay, so that is
very interesting. But now we can actually
make stuff happen by touching a specific object. So we could e.g.
in the micro part, Let's actually make this anchored so that it
stays in the air. So now it's floating. So it's never going to
be touching the ground. And then we can do we
can do anything we want. We can print something out. We can let it start moving. We can shoot the player
up into the sky. I mean, there's all sorts of things because this
other part, right? We always have
access to the thing that has touched our part. Therefore, we should have access to the player in some capacity
or the character, right? So we can do something
with it as well. In our purposes,
the only thing that we're going to do is
we're just going to make the object
transparency less. So we're just going to say, we're going to make the
transparency equal to one that So basically it's going
to change 2.5 anyway, and then we'll change it to one once this actually
touches something. So as soon as I jumped onto this object or I just brush it, it's going to basically disappear because the
transparency is gonna be one. There, there you go. It's gone. Now it's of course
not gone, right? It's still there,
but it is invisible. So that is pretty
cool that you can change certain
properties now as, you know, as something is
happening inside of the game. So now we're no longer
just changing properties, are actually responding to things that happen
inside of a game. And now just because it is
a very fun thing to do, what we're gonna do
is I'm now going to actually use what
we have so far. I'm going to make a Boolean
property is moving over here. And I'm going to ask, well,
if moving is equal to false, then I actually want
to do the following. I then wanted to, first of
all put moving to true. And then I want to make
a for-loop over here. I is equal to one and then
we'll do ten and we'll do one, and then we'll do. And what we'll do here
is we will wait for 1 s. And then I actually want to
say my part that position. And then I want to
change its position. So we're going to simply
go with plus equals. Let's say plus equals
and then just say vector three dot menu and
then just one zeros, zeros. So once again, we're just
going to move it into the X-direction by
one n at the end. After this for
loop has finished, then we want to say
moving is equal to false because otherwise we will never be able to
reset it basically. And then it's going
to, it's not going to work basically the general idea, but this, alright,
if we do this, now, when, once we
touch the part, it's going to start moving
into the x-direction, ten blocks for 10 s, and then it's going
to stop and then we can actually move it again. So let's just see for the
sake of argument here, right? So nothing should
happen all this fine. I touched this after 1 s. You can see now
it starts moving. Now I don't know what's
going to happen once it arrives here on this spawn pad. I'm actually quite, Oh,
what's going to happen? And it's going to stop. It is now stopped. And
I can touch it again and it will continue
to move about. As you can see. This is clear, isn't it? Because it's done again. And if I touch it
again after a second, you can see it continuous. So this is really,
really freaking cool. That is an awesome thing that is basically working here
in this case is actually an example of how you can respond to something happening
instead of the world. To summarize, an event is
attached to a certain object. And if that object, if that event is fired, depending on what happens, then you can actually
connect a function to it, and you can call that function every time that particular
event is caught. In the case of the
Touched event, e.g. this actually allows you to now respond to things that
the player might do, insert the world and then
do certain things with it. Well, that's gonna be it for
this lecture right here. I hope you found this
useful and you'll learn something new
and I'll see you all in the next
lecture. So, yeah.
23. (Roblox) Creating Instances from Scripts: All right, let's continue
the roadblocks basics here for the Roblox course. And in this lecture,
we're gonna be taking a look at spawning new parts. So what is spawning
new parts mean? Well, we're going to
spawn hearts via scripts. So first of all, in the
server script servers, we're gonna make a new script
and we're going to call it 09 dash spawning. How about that? And we'll
call this spawning objects. There you go. And what we'll do is we will
just spawn a new object. So we'll just spawn new parts. And let's first of all do
it in the script itself. And then we're gonna do it
on touch in a little bit. So how would we
spawn a new port? Well, let's just make a
local and call it new part. And this is going to be while a new part,
how do we spawn it? We're going to say instance, and you can see it already
suggests this to us. We can autocomplete this by
pressing the Tab key new. And then inside of here, we
have to get the class name. So we have to put in the
class name as a string as soon as I start typing
in the quotation marks, you can see we can
actually choose, well, a whole lot of different
classes that exist over here. So we can add a new
air controller, a new vector three value, new module script
if we so choose. But in our case we
want a new heart. In this case, we're just
going to choose a new part. And what happens if
I were to do this? Let's just play and
see what happens. And what you will find is that, well, nothing really happens. Let's see. There's no, there's
no new parts. So nothing really happened
because this part, in this case, it's sort
of created nowhere. So we can change the
properties of this part. So we can say e.g. name is equal to a new part over here, right? So now we have given it a new name and we can even
change the position, right? We can say while the position
is now vector three new and let's say 0150 or
something like that. And we also want to make
it anchored, right? So we're going to just
make this anchor. And now in theory, if
all of this is fine, then we should see it roughly
hovering above the spawn. And you can see nothing. And if we look in the workspace, you can also see my
new part is not, is not part of this because we actually need to set
the parents as well. This is extremely important. So parenting literally is just the idea if you look
at the explorer over here, but the referencing script or to referencing and
all my other scripts. The parent of this is the
server script servers. So you just see that
is the relationship. You can also see the
parent right here. And if we go into the workspace, you can see the micro part, that parent is the workspace. And if you go into
the base plate, if you go one further down, the texture here, that
parent is base plate. Which base plates? Parent is the workspace. That is the general
idea. This really should not be
anything confusing. It just basically shows you the hierarchical structure of the explorer, and that
is pretty much it. And now if we say new part, parent is equal to
game dot workspace, all of a sudden we're
setting it to the workspace. And now let's see if we can
actually see our new part. And what you will find
this all of a sudden, there it is, there's
our new part. If we go into the workspace, we see a new port, exactly the same name that
we've given it right here. And we've spawned it
completely through a script. And usually this is always the order that you want to take. So basically, you want to
create the new object, then you want to set some of the variables over here, right? So we're going to
changing the properties. And then this is
always important. We want to set the
parent, right? And this is like a very, very important thing that we
want to set the parent here. Otherwise, it will not
be displayed at all. Now, what if we were to do
something interesting, right? What if we were to just get
the Touched event, right? So we're doing the
same thing over here, but instead of moving, it will actually do
something different. So what we'll do is
we'll just copy this over and I will just comment
this out because well, in this case, I
actually don't want the thing to be connected
to something else. We're gonna do this
in the spawning. So we're just gonna
spawn one object. And then we're
going to say, well, you know what let's
do, instead of moving will actually
spawn something. So in the Touched event, when we were touching
my cool part, I now want a new
ports to be created. So we're just making
a local Newport and we can do almost the same
thing as this one, right? We can just say,
Hey, in Newport, and let's just call this, let's call this another Newport. And let's put a 015. Let's phone and actually
I'd like something like 20 and in this case will
not make it anchored. And then let's
actually put this up, push this back a little bit. 525, okay? And then we still need to
parent it to the workspace. And we'll also add a little bit of a weight function over here, let's say half a second, because otherwise we'll just
get inundated with new, new fricking parts to a little
bit of a delay over here. But now what this should do
is as long as I stand on the, on my cool part, right, it's going to
Swan new parts in. So let's just see that does anything but I'm pretty
sure that it will. Once again, we have our
part that we had before. And if we were to jump on this, you can see, all of a
sudden, they can see. And now you might ask yourself, Wait, why does it
spawned so many? We specifically made it so that the weight function is in there. So if I were to
just stand on this, but so you can see it's
not spoiling anything. And if I were to
move around and you can see that it is working. And the reason, of course,
is that the Touched event, in this case, it's actually
called for each part, right? So basically we're saying
it doesn't even matter what the part is that is touching
our micro part here. For each one of those, we're spawning a new part. And we've seen previously
that the player is made up of tiny, tiny
different parts. Therefore, this is going to get called an insane amount of time. So to quickly summarize, when we spawn a new part, in this case, we can do instance dot new and important
in this case. Or we can also spawn
almost anything else. We can spawn a whole host of different types of classes
is what they're called. They're just basically
saying, okay, what type of part or what
type of object is this? In our case, we just want to port and there are
other ones, right? The spawn location as its
own class, things like that. So we could also spawn
these things as well. In our case, we're just sticking to the
parts at this point. We can then change
the properties. And then very important
that we set the parent of the new part that we've just
spawn to game dot workspace, otherwise it will not display. And at the end here,
we've seen that we can also connect this to
the Touched event, which is really awesome. So now we're spawning things when we're actually
interacting with the world. Pretty cool, but that's gonna be it for this
lecture right here. I hope you found this useful and deodorant and the
new one I'll see you all in the next
lecture. So, yeah.
24. (Roblox) Click Detector: All right, let's continue
with the Robo space X here, follow rule books course
and in this lecture, we're gonna be talking
about click detection. What could this be? Well, well, well let's create a new script in the server script service. And we'll call this ten
and dash click detection. And this is going to
be very interesting. So click detection,
what does that mean? Well, you have probably played one or two games where you were able to click on something. And this is exactly what
we're gonna do as well. So we will just create a
new part in the workspace. First of all, let's create
a new part over here, and let's take this and let's actually size
this up a little bit, just so that we know that
this is a different part. Let's actually make this 55.5. There you go. And then we'll also colored
a little bit differently. Let's do this. Blue
is kinda nice, but let's make it a
little bit more blue. Yeah, there you go. Are also
make this anchored so it keeps floating in the air like this and I'm actually
okay with that. So we now have a floating port and we will rename
this to clicker. And what this part needs is it actually
needs a sub object. So we're going to click
on this plus over here. And you can even see
if frequently use click detector is exactly
what we need to add to this. And you click detector just
has a couple of things, namely the max
activation distance. We'll talk about that
in just a moment. But now we have a click
detector on this. What we wanna do is we want to actually get that as a variable. So let's get the click detector,
and this is a variable. And now we're going to go
to game dot, workspace dot. And then we need to try
to find the clicker. So we're going to use
the clicker part. And then because
the click detector here is a child object
of the clicker, we can actually get the click
detector as you can see. Awesome. So now we have the click
detector right here, and this refers to this
particular clip detector. And now we can just
make a new function. So let's just make a
new function on click. And we'll also put in the player because
this is actually what we are going to get for
the function, right? When you click something,
we're actually going to get the actual player
that clicks this. So first of all, let's just
print out this player. Click Me, and then
just print out player, just, that's all that
we're going to do. And how do we connect this? Well, once again, the
click detector in this case has certain
events over here, right? So we have, and we have
actually quite a few. So destroying, those
are normal events, but then there's also the mouse-click event
and the mouse hover, the mouse over leave and
the right-click event. And the, I believe that
those are the main ones. And that is pretty awesome. Actually. We're going to use the
mouseClicked event once again using connect here. And then we can just
put the onClick method inside of it without
the parentheses though. So we just want to pass
this in like this. And then when we click on this, we're actually going to
execute this function. This is the same idea that we've seen in the Touched
event before, where we connected a
inline function here. We just created the
function right here. But in this case, we have made the function before and then
we're putting it in there. It's the same idea. Now if this is all the case, then let's just play and when
we actually go over there. So the first thing that
you will be able to see is that when I hover over
this with my mouse, you can see it turns
into a hand because, well, this is now clickable. If I were to left-click, you can see this
player clicked camera. So now all of a sudden
the server is like, yeah, the player clicks this
particular clip detector. So that is really awesome
because now all of a sudden we can interact with the game to a whole
nother level. In this case, there's
actually a second way that you could feasibly do it. And that is you can add a
script to the clicker itself. So you can call this
the clickers script, let's say, right. And then let's just take the same thing that
we have in here. And let's just add this
to the script over here. So this is now the
click detector, but we can actually do something different. We can say script. This is taking our script
inside of our hierarchy. And I'm going to say parent. And then we're going
to say click detector because this script, right, we're gonna go to the parent
which is the clicker, and then we're going
to click the texture. This will also work. So if I were to just, Let's say, let's actually comment
this out because that's a little bit better if we do this. There we go. So this is
commented out and then we have the clicker script as a
child of the clicker. And we can also do this. And let's just see, in theory
this should still work. And if we go over here, you can see we're still getting this output and that can
sometimes be better. So before, of course we put everything in the
server script service. So it might just make
sense to actually have the script below
our clicker part. Because maybe if we
were to duplicate this, and then we have a
second one here. Now, this one also works without me having
to do anything. Now there are two different
scripts, and of course, now the issue comes
in that you have to keep track of which script
is which and all of that. But regardless of that
though, it is kinda cool. You can also have this script below the actual part.
That's not the main thing. Of course the main thing is
the clicked detection itself, which is another way that
you can interact with the world now and now we can use what you've
learned so far, right? Moving things, sending
the position and you can make something
clickable and you can change positions, e.g. right. So just for the
sake of argument, I have created something here that might be
kind of interesting. So if I just play this and
let's, and I'll show you. So if I go over here, right, we have this red
cube at the top. And if I click this one, the red cube shifts
over to above this. And if I click the left
one, then it shifts back. So basically just a way of changing this particular
cubes position. That is a pretty cool thing. Now I'm actually not
going to show the code. The code will be
available so you can download it and
you can download the Excel file with this particular moving
part display in it. What I would say is
that, first of all, try to create this yourself. And if you can do it, that
would be absolutely amazing. If you are stuck, you can always
take a look at it. It is basically two clickers over here on the left clicker
and the right clicker. And it is two scripts. However, the scripts are
literally exactly the same. So there might be a
way of condensing this into one script for
the time being though, just trying to see
if you can figure out how to create this. Because that would already
be really cool way of solidifying some of the things that we've
learned so far. So in summary, the
click detector is a really useful tool that you can use for further interacting with the
world and Roblox. And it can be used
for anything really. You can just make a
new function that is then called when the player
clicks on a click detector. And that can do anything
you want, right? But that's gonna be it for
this lecture right here. I hope you found this useful and you'll
learn something new and I'll see you all
in the next lecture. So, yeah.
25. (Roblox) Applying Forces: All right, let's continue with the Roblox basics here
for the robotics course. And in this lecture, we're
gonna be taking a look at force and everything to
do with that basically. So what does force will
force is basically adding a force to
a particular part. And we'll just take a look
at an example of this. So we're just add a
new part over here, and we'll call this the forceful part for the sake
of argument here. And what we wanna
do for this part, well, we want to move this. First of all, we want
to size this up though. Let's size this to 444 again. And then we can add a, well, we can add a lot of
things as we have seen, but if we search for force, you can see a force-field. Now, we don't actually
want to add a force field. We do want to either add a
line force or a vector force. Now those are almost
the same thing. There's a slight difference, but will first of
all take a look at the vector force and then we'll look at the line
force in a moment. The vector force in
theory simply points to one vector and basically then shoots this part
to a particular vector. However, we need an attachment. So you can see this is an
attachment that is needed. And the force that is being
applied as applied to, in this case, 1,000
to the x-direction. So it would all of a sudden
shoot in this direction. So let's just set it down here. And if we were to
just play this, you will be able to see
that, well, nothing happens. So you can see the part
over here, nothing happens. Let's change the color
to yellow in this case. And we will be able to
see that in theory, it should shoot in
this direction. However, it does not because
we don't have an attachment. So actually to
this force report, we need to add an attachment. You can see we can just search for this and we can
add attachment. And now the attachment is a
part of this particular part. Now, if we were to move the
attachment, you can see it. Alright, now that attachment is directly in the middle of this, which is usually what
we actually want. So we can just say attachment. We can click on this, click on the attachment and you can
see now this is attached. Now if we want to make sure
that this is the right one, we can also rename this
forceful part attachment. And if we were to look
in the vector force, you can see forceful
part attachment. Okay, let's play this and
let's see what happens now. What you will see is that
this still is not moving. So you might be like,
that's kinda weird, right? Because we can move it,
but it's not moving. Well, the issue is that
there is friction between this part and the base plate because of course
there are touching. And you can imagine this
if you have a cube that's laying just like on
a table to move it. That's not gonna be that bad. But if it's like a
rubbery surface, that's gonna be a little
bit harder because there's different
amount of friction. So if we were to
increase this force to, let's say something like
3,500 here in this case. I'm pretty sure that
should be enough for it to start moving in
the x-direction. And you will see, there it goes. And it frequent zooms
off to the skies until, well, until it's gone basically. So that is pretty cool already. Let's try to do 2,500. Maybe that's going to make
it a little bit slower. And maybe then we can actually
see someone else as well. 2,500 is apparently not quite enough over
here as you can see. So we need to do a little
bit more, but that's fine. Let's do 3,000 and then that's hopefully not gonna be too fast. And then we can
actually expand this. We can see forceful part. You can see the
velocity actually is something because it's moving
in this direction, right? It's actually having a
velocity because a force is being applied if I
were to increase this. So let's just say it was 50. Now the part is gone
because it's flown off the floor of the sky. And if we're just
restart this and go into the workspace quickly and
change the force over here, let's say 5,000, right? All of a sudden where
we got an insane amount of velocity now and
it's way faster. Now this is a way of
moving a part, right? With a force. That's really
interesting already. To have this, There's a
different type of force. We can also have, We saw this. There's a lion force. So the difference
here is subtle. Vector force basically applies a force in a certain direction. In this case, the x-direction now does this relative
to the attachment. You can also do with this
relative to the world. The difference here is that
if we were to rotate this, right, so right now we're
using the x-direction, which is this
structure right here. Which is fine. Because the
extraction of the world is this way and the x-direction of the attachment
is also this way. If we were to rotate
the attachments. So I've now selected
the attachment and I'm rotating it
by 90 degrees, right? So let's just
double-check over here. Modal rotate 90 degrees. I've just checked this. And if I were to rotate
it by 90 degrees, all of a sudden the x of the attachment is
in this direction. Now we're getting all sorts
of confused because, well, the force, right, Let's just get rid of the line
first for a moment. The vector force is using
relative to attachment. So now we're going to zoom
off in this direction. If you're like, wait what
the heck is happening? Well, let's just take
a look and you will see it's now not zooming
in this direction, but in this direction. Because the force is
being applied locally, because we have
world coordinates. So the world in this direction
is x, this direction is z, and the up direction is why that should all be
more or less fine. But then you also have directions for your
own parts, right? Because if you rotate apart, all of a sudden it's rotated. You see, this is now x, this is x, this is z, this is y. That's all fine. But if we were to rotate it around 90 degrees around
the x-direction, right? All of a sudden, y is now different because we've
changed the rotation. So if you change the
rotation of something, you change its 3D local
coordinate system ran a pretty crazy
thing, but overall, hopefully somewhat
understandable that there is a difference between a local
coordinate system and the global
coordinate system. And this was the vector force. Let's actually talk about
the other force as well. That is the line force. Let's just disable the
vector force here. And the line force needs to
attachments as you can see. So what we can do is we
can just make a new port. This is going to be the, this one right here, and
we'll make this yellow, but like orange,
that's gonna be okay. Let's scale this up just a little bit. Something like this. I'm actually fine with. And if we were to, let's say rotate this
around a little bit and move this about two,
something like this. What we could do is we
can add this is going to be the line of force part. Just to demonstrate this, we want to add a, another
attachment to this. Now this attachment once again, is in the middle of this. We can move the attachment and you should be able to
see if we do this. Let's rename this as well. Line force attachment. We can now move this as well. And you can see it is a little dot over here that
you will be C. You can also make this visible and then it's always
gonna be visible even if we have not selected
it sometimes can be useful. So if we were to just move this about like at the top over here, what we can now
do is we can take the forceful part attachment and attach that to
the other attachment, the labor force attachment
make a line and then this particular object is going
to move across that line. So it's going to basically pull the first attachment here. So if we go to the
line force, right, it's going to pull the forceful attachment
towards the line attachment. If we do a reaction
force enabled, this is an important. And then magnitude once again, is just the idea of
how fast it is going. So if we were to just run this, let's see if this does
anything any will see, nothing happens but 1,000 was
probably not high enough. Let's just do 4,500,
something like that. Maybe that's gonna be
enough in this case. And that is indeed enough. And you can see it's
trying to get to this. However, it actually can't get up due to gravity
in this case. So what we could do
is we could also get this higher so we can make
the line force even stronger. So we could do
something like 7,500, maybe not 75 K, that's a little much 7,500,
maybe something like that. And we can see if
that does anything. And now it's like it actually
knocked over the pinna, which is also kinda funny. But you can see
basically it is drawing a line from the middle of this cube all the
way to this one. So from the forceful
attachment to the other one. So these are the two
types of forces, in this case, vector
force and align force, both used with attachments, which are also quite interesting because you can do a lot of things with attachment
is actually, and we will see quite
a few things with those in future
lectures as well. So to summarize, overall, there are two types of forces, the vector force
and the line force. The vector force simply
applies a force in a certain vector direction
for a particular attachment, the vector direction can be relative to the
attachment itself. So it's going to
change the direction depending on the rotation
of the attachment itself. Or it can be relative
to the world, which means that the objects, the objects orientation
or rotation does not factor in which direction the force is being applied to. There also is a line force which actually uses
two attachments. So it basically
applies a force from one attachment
towards the other. So draws a line from
one attachment to the other and then applies
a force on that line. And that's going to be it
for this lecture right here. I hope you found this useful
and you learn something new and I'll see you all
in the next lecture. So, yeah.
26. (Roblox) Constraints: Alright, let's continue with
the Roblox beginner section here for the Roblox course. And in this lecture,
we're gonna be taking a look at constraints. Constraints are a very, very interesting
thing that you can add in your workspace again, that is going to constrain
the movement of your parts. Now, this is going to be a very surface level overview
as an introduction here, this is, can be, I mean, this could have its own like
two-hour lecture in theory. So we're just going
to add a new part and we will just make this, let's say like a little
bit of a darker orange, maybe a little bit
of a darker orange. There you go. And we're going to
just scale this up a little bit and we will add
an attachment to this. So this is going to be the con, drained part and this is
going to have a constraint. First of all, it's going
to have an attachment. Actually. This is gonna be the con, streamed attachment just so
that we know what this is. And then we can
search so we can, so we can add a thing
to it and we can just search for constraint. And you can see there are
a bunch of constraints. As you can clearly see,
balsa can constraint. There's a cylindrical
consent hinge, no collision play in
prismatic, rigid, like there's all sorts of
things that you can have here, and those do different things. E.g. the rope constraint makes a rope between
two attachments. So in our case,
we're going to have the first attachment
B, our own attachment. And then let's see. The second attachment
is the attachment for our forceful part. And then you can see
all of a sudden it makes a rope between them. So if I actually
enable the visibility, you can see this is
now a rope that is spun between this attachment
and this attachment. And the rope is really cool. So you can have
different thicknesses. So this would be a really
thick, thick rope. So let's put it back to 0.1. You can change the color of
it of course as well, right? So if you have a
different color of rope that you want,
that also works. And then there's some
interesting things and that is the
length over here, the restitution, as well
as the winch enabled. If we enable the
winch, then there's a few more attributes
that we can use. But let's just see, Let's just make the length so you can see if I
increase the length, ten is nothing but if
I do two, Wendy, e.g. if I do 50, Let's go. Okay, So, so 20 is
not quite enough, but 30, not quite 40. And then it starts to
sort of slack over here because it's longer than it
actually needs to be, right? So if I were to do 32, something like that,
it's still taught. 35 is already sort
of going down. So you can see that because the rope has
a certain length. If I then move it,
you can see it. It actually is. It's
taking into account the length of the rope
when it's displaying it. So that's really,
really cool, right? And what will now happen? Let's say I make this particular
part over here anchor. This means this guy does not move like whatever
you freaking do. But what is going to
happen is I'm going to re-enable my vector
force over here. So the cube wants to zoom
off in this direction. What do you think?
What's going to happen? Let's just take a look and
see what's going to happen. So we will find that the cube, while it's trying to move
into this direction. But of course it
can, because it is constrained by the
rope constraint. This is really awesome. And you can do some
interesting things with this. So that's an example of
the rope constraint. Like there's so many constraints as you've clearly seen, right? One other interesting constraint is the spring constraint. This is this one right here, and this is a little
finicky to use, but once you understand
it is really cool. First of all, for this, I'm actually going to move the constraint
attachment down a little bit just because it's
just so that it's like on the same level
as the other one. So this would be, where is it? This is minus four. So the word position
is actually 1.5 in the y and the world
position here is two. So let's just add, make this 12. There you go. And now it should be
on the same level. And then we can actually attach this attachment
zero is once again the constraint part
and attachment one is the forceful port. You can see there's a spring
now and we can change the appearance over here
by adding some more coils. We can change the
radius over here to craziness and the thickness
to something really thick. Again, let's just
make this always visible just so that we have
this for the time being. And this is only appearances. So this doesn't change anything when it comes
to the functionality. The functionality is then done
over here with the spring. So the current length is 16. So let's just say that
the three length, this is basically the
length that you want. This, you can see
actually it's the length at which the spring exerts
no stiffness force. This means that it
is not going to push this particular object
anymore. And that's fine. If you say 16, then if we were to just run
this, nothing will happen. And also it's zero stiffness, so nothing will happen anyway. But if we were to set
the stiffness to 1,000, let's say let's put dampening up to like five,
something like that. And let's just play this. Oh, but before we start, let's
disable the vector force, just that we have this disabled. And then let's actually go
in here and you will be able to see that
when I am in, right. So right now nothing
happens if I were to try to put this in here
and look at this, right. All of a sudden it
bounces back, right? So I can move this. Towards the spring. And it is always
going to try to get the distance that is defined
in the constraint over here. So you can see current
distance is 17. I can make this smaller by
basically pushing this right. And then it's going
to extend again. Now the current length
here doesn't change. It probably only
changes on the server, which is actually kind
of an interesting thing. So let's actually see if
this is indeed the case. And you can see that you can do some pretty
insane things over here. But yeah, it does
change on the server. So that is good to know. But yeah, so this is one of
those things that you can do, some really interesting
things for this to work. Of course, the spring
constraint needs a high enough stiffness and a certain three
length basically, right? So if we were to decrease
this free length, all of a sudden, it's going
to pull this back because, well now the free length is
12 and it's going to try to get the current length to
roughly be the free length. Not exactly, but as much
as it can basically get. And because the
spring in this case, once to actually
keep an equilibrium, both of the like, it doesn't want to be too long and it also doesn't
want to be too short. You can also enable limits. So this would be the
max length, right? So you can, the maxlength
is less than free length, doesn't really make any sense. So you can say something
like 20 and minlength, you can say something
like five and then you can't even move it
closer to that. So if we were to now move this in over here
just a little bit more. Let's see something like
this that's going to be easier than if you tried to less than five,
Let's actually do ten. Maybe that's gonna be
a little bit easier and that's not even
going to work. So you can see there,
I actually see, I can't even like push this
anymore because that's like the actual minimum length. If it's zero, then it can
be as short as you want. So what I do highly recommend
with the constraints, especially the
spring constraint, because that can sometimes be, there's a lot of things that
you can change over here. I highly recommend playing
around with this a little bit, including some of the
other constraints. So the row constraint is probably one of the
easiest to work with. The spring constraint is a
little more complicated, and some of the other ones
are even more complicated. However, they do enable almost all sorts of
physics-based things. So in theory with the spring constraint and
some of the other ones, the hinges and the
cylindrical it constraints. You can actually
built like physics, simulated cars and
stuff like that. That actually like our
simulated with actual physics. It's insane that that
is a thing that works, but it does work. But that's something for like advanced, advanced
people, right? Like that's nothing
for us at the moment, but it is pretty cool. So I can just highly recommend
playing around with some of the constraints a little bit and just seeing what
you come up with, that is basically always one of the best ideas to learn
how this all works. To summarize, there are multiple constraints that you can add to your parts and then
add two attachments. And it can constrain the parts on how they are able to move. There are many different
types of constraints. We've seen the rope and
the spring constraint as two examples over here. And once again, we'll mention, I highly suggest
just playing around with some of them and then you hopefully we'll be able to find some cool uses for them as well. But that's gonna be it for
this lecture right here. Hope you found this useful
and you learn something new and I'll see you all
in the next lecture. So, yeah.
27. (Roblox) Spawn Points: All right, let's continue with
the roadblocks basics here follow robotics course and
in this short lecture, we will talk about adding
a new spawn locations. So of course, adding
a new spawn location. That's nothing like
that's insane, right? You can literally just
do it by going to model spawn and then
there's another spawn, or you could duplicate the
already existing spawn. What happens if you
have two of those in the same place? Well,
let's just play. And we'll obviously see
that I spawn right here. So I spawn next two are
clicking Game over here. Let's just stop and
let's play again. And let's just see
where it's born now. Now I spawn also next
to the clicking game. So that is pretty cool. And let's born again. And let's hope that the
forces of randomness are on my side because now I've spawned not next to
the clicking game, but actually next to the spring over here,
which is pretty cool. So the idea is that if you have multiple spawns that
are the same team, what's going to happen is
that you're just going to be assigned one
of them randomly. If you select one of the spawn locations and
you go all the way down, you can see there is
something called allowed change on touch and
also the team color. So for this, you
actually need teams. We're just going to
take a look at this. So in our Explorer, we can actually add some teams. So we can add a team.
We're just going to call this team red. And then we'll also add
another team and that's gonna be team blue. Team blue. We're just going to make
this a bluish color. And the other one, we're gonna
make this a reddish color. Really ready, I like
that's, that's pretty cool. And this is pretty much
all that you need to do. We can make the auto
assignable turn on or off. Let's just keep them
on for both of them. And if we now go to the
small location, right? And we go down, we can change the team color, really red and we can say, Allow team to change. And then we can go here
and we can also say this, and this is going
to be the blue one. I think it was this
way, electric blue. I'm pretty sure we
have our two teams. However, right now,
the spoons or neutral, we want them to be not neutral. So when you spawn, you have certain teams that
are associated with this. So let's just go in here. So right now I'm in team red
because I spawn right here. If I go to the other spawn and I touched the other span, all
of a sudden I'm Tim blue. Let's go and I can go back
and go to team red again. And you can even see that
you change the teams. Now this is not always
what you want, right? Might be, maybe
you actually don't want people to
change their teams. So then you just say, Hey, you can't allow the team
change to appear on us. So that does work. So you can just turn that off. And also what's important is that if we were
to change this to, let's say, really blue now instead of electric blue, right? But if I have this turned on, the team color is going
to be electric blue, but the team blue is actually going to have the
team color really blue. What's going to happen
now? Let's just see, I'm going to small team red. And if I go over here, this is now changing the team. You can see it changes me to neutral because it doesn't
find the team color. This is very important. So this is an important
part about this. So basically, if we go in here, the team color right
on the spawn location, this actually has to be
exactly the same team colors. So this would be electric blue. And then this also has
to be electric blue. Those team colors are
basically matched. This is also why you can have two teams with the same color. That is actually a very
important part about this, but that is the
general idea of adding teams and new spawn locations. Now, what you would want to
do in the good thing to do is actually to create all of
those teams and all of those four locations
via a script. That is also a smart idea. We're not gonna do this
for the time being. I just wanted to show
you basically how to add another location and also
how to take a look at team. So that's gonna be it for
this lecture right here. Hope you found this useful and you'll learn something
new and I'll see you all in the next
lecture. So, yeah.
28. (Roblox) Player vs Character: Let's continue with
the Roblox basics here for the roadblocks course. And in this lecture
we're gonna be talking about character versus player. So what is a player and
what is a character? We have seen the players
over here in the Explorer. And if we join, then we actually can see that there is something
added and that is countable. So there's me, I'm
added as a player, but if we go into the workspace, I'm also added in the workspace, which
is pretty interesting. Let's take a look at this from
the server's perspective. So in the server we can see
we also have the player come through and we also have
the modal kilometer. So they can see this is a model, while this over
here is a player. So what is now the difference
between the player over here and the model
or the character, like what does each
of those things. So the player actually contains
what Player data, right? So this is going to
be something that's unique to me in my user ID, I have a team, right? So this is specific
to my player. While the character
or the model is just the physical representation
right here, right? So this is gonna be, this is
the model or the character, and this has different colors. It has, it has a health set, it has a humanoid component. And the humanoid
components as responsible, as you can see for
some of the scaling, for some of the width,
this even description. So you can see there's
different accessories. So this is all of
the visual things. This also includes scripts, as you can see, local
scripts like animate. So this is basically all
of the animations that you see when I move
around over here. Those animations, right?
The walking animation, the jumping animation,
all of that, That's all done via the
animation over here, this guy, which I can
actually go into. So you can actually see, this is the animate script
that's already in here. And you can see there's
a lot of stuff in here. So as you can clearly tell, some of those scrubs can
get pretty fricking crazy. So overall, when you
really think about it, what's important is
that the player, if we want to add
any type of values, they're added with the player While anything else is
added to the character. So you can see,
if, you can see if I expand the player over here, there's a backpack over here, there's some starter gear. So if you have gear, right, you would save it in
the player and it would be displayed in the
character or the model. So if for whatever reason
you wanted to change the way that our
character looked like, you would need to
actually reference the character and
not the player. Now you can get the character
via the player, right? Because if I click
on control here, you can actually see that we have a character
reference over here, and that is collegial, which is exactly this guy
over here, right? So they are linked. You can get the character
from the player. But that is the general idea. So to summarize, the character is everything that's visual. It basically has a reference to all of the models and
all of the humanoid stuff, and it is available
inside of the workspace. In theory, however, you would
always go via the player. You'd always wait
until the player has loaded or
something like that, and then actually go via the
player to the character, because the player
has a reference to the character and
the player itself is basically the actual client and has all sorts
of inflammation, including some
value store on it, which will actually see
in the next lecture. Well, that's gonna be for
this lecture right here. I hope you found this useful and you'll learn something
new and I'll see you all in the next
lecture. So, yeah.
29. (Roblox) Saving Variables on Player: Let's continue with
the robots basics here for the robotics course. And in this lecture, we're gonna be taking a
look at how you can save certain variables
on your player. Now this at first might
seem a little bit, and that's kind of
not really useful, but it actually is very,
very interesting indeed. So where can we
add those values? We want to add those values
to the starter pack. So what you can do is you can
add values as you can see, if I search for values,
you're going to add color values in values numbers. So there's a bunch of things
that we can add over here. Let's just say we
add an end value and let's just call this. I experienced just for the
sake of argument right here, just so that we have
something to work with. If we were to now
start playing, right? And if we were to look into
the player and calm Joel, and then into the backpack, you can see I've got some
experience in my backpack. Now, of course, in this case, experiencing the backpack
doesn't quite make a lot of sense conceptually, but just think
about it as, okay, you will now have some
experience added to your player. We're going to see this
in the next lecture in a little bit of a nicer way. But just for the
sake of argument, we're going to keep it like
this for the time being. Now, right now, we can really do anything
with the experience, like it doesn't
change your mind. I guess we can
change it here, but that doesn't do anything, right? But what we wanna do is, let's just say that we want to change the experience every time I change the position over here. Let's say when I jumped on the other
block over here, right? So this would be the
touch block, right? If I jump on this, instead of exploring
1 billion things, would actually want to do
is I want to just print out the actual experience of
this particular player. Okay, that sounds, that
sounds very interesting. Now, in theory, you should already be able to
do this on your own. But let's just go through this. Now first I'll actually
make a new object over here and we'll cover this
a little bit differently. So let's color this in a little
bit of a different color, maybe a little bit
more dark red. Yeah, that's good. Burgundy. Absolutely. This is burgundy.
We'll keep this as a clicker with
another script. This is actually going to
be the experience clicker. And this is going to
be the experience, experience clicker script
because this is actually going to output what the actual experience
of the players. So now we have the
player here, right? When it clicks on this, we
can actually do player dot and then we can do backpack
and then dot experience. Is this going to work? Well,
it's going to look for this. And as long as we've written
everything here correctly, then this should work, right? So we should be able to
say this player, right? And then we can actually
do player that's going to output the player's
name has XB, right? So this should be output,
this player council has, and then whatever experience we have actually inside
the backpack. Let's just see if that
actually does anything, right? So let's go in here
and let's see, where is it right here. So if I click on
this, we should be able to see this count, this player count row
has experienced XP. Okay, well, that is
not quite workout as we wanted it to because
our experience here, right, this is an int value. We actually need to do dot value and then we get the
value because of course, when we just get experienced, we just get the name, right. So it defaults to the name and we actually want
to get the value. So now in theory,
if I do this again, if we go into here
and we click on this, then we can see this player come through, has
zero experience. That is a very, very good first step. Now let's see how we can
increase the experience. For this. We want to change both the clicker left and
the clicker right. There you go. And for this, once again,
we get the player. So we can just change
the experience, right? So we can basically just take this player backpack
experience value. So this is the experience. And when this, when
the player clicks, we just wanted to increase
the value by one. That is literally
all we wanna do. Okay, let's do it here, and let's do the same
thing right here. And that should be pretty
much what we need. So now the value of
the experience is increased every time we click on the left
and the right one. So let's just see if this
actually does something. First of all, just to
check somebody check hasZero experience that
is absolutely correct. If we go to the
player over here, look in the backpack experience. Now, I click on this one. You can see all of a sudden
I have one experience. Now I have to 3456 and I can actually click
on the same one and get multiple
experience of course, but this is just an
example in this case. If I now click on this, you can see I have
16 experience. Yeah, that's really cool, right? So if saved value on the player and it is
now being stored. Now if I were to
stop and sort again, we'll, of course, it's
going to be reset, right? If I go back over
here, welcome back. This is zero once again because we're not
saving it anywhere. That is something that
we're actually going to take a look at an
intermediate steps because we actually have to save this onto the roadblocks Cloud, which is a little bit more
complicated in also comes with some other things that you have to
really look out for. But right now, you have saved a particular value on the player with an
int value over here. And once again, I can show you there's different
values that you can have. Boolean values, color
values, and values numbers. You can even have object
values, vector three values. So it's pretty cool what type of values you can
store on the player. And you can basically
enhance your game with that at statistics or
attributes to the player. Now this is pretty cool already, but in the next
lecture we'll actually see how you can add
the leader sets. So this would be
adding the stats on the leader board on
the top right, right. If I join in here, we, we've seen the
leaderboard because we have different
teams and I can add certain values to
that leaderboard as statistic and then
change those as well. And then we can
actually see them like more or less in game. So we don't have to
basically go to like a random stone and click that to see how much
experience we have. We're actually going to be
able to see this in game. So once again, that is
pretty freaking awesome. Our, that's gonna be it for
this lecture right here. Hope you found this useful
and you learn something new and I'll see you all
in the next lecture. So, yeah.
30. (Roblox) Leaderboard with Leaderstats: All right, let's continue the Roblox basics here for
the world works course. And in this lecture,
we're gonna be taking a look at a leaderboards, or also called a leader stats.
This is very interesting. So for this will actually delete the experience that we've
put into the starter pack, because this time will
actually generate all of our different
values via a script. So in the server script servers, we're gonna make a new script
and this is going to be 16 dash liter stats. And let's just add, this is either a leader board
or leader stats. That's the general idea
and this is actually very important that we do
all of this correctly. So first of all, we'll
have a local players and this is equal
to game players. So this is going to take a
look at this one right here. So the players over here,
and it's going to get this. And what we can do is we can make a local function over here. And this function is going to
be the leader board setup. And this will happen
for every player and it's going to
look like this. So we'll make a new folder. First of all, it's
going to be called leader stats and then
the folder itself. So this is a new folder and
this is an instance dot nu, and this is a new
folder. As you can see. This is just a new folder that's going to be created for each of our players will see
how they're going to be added for each player
in just a moment. But first of all, and this
is extremely important. The name over here has to
be exactly liter stats. Please pay attention to this. Has to be written
exactly like this. Lowercase L, Liters stats. There's no space in-between, there's no dash,
exactly like this. I've seen this so many
times that people are like, Oh, I don't know where
it doesn't work. It's because it has to be
written exactly like this. Once that is the case,
you can then set the leader stats dot parent
equal to the player itself. So this is going to set the
folders parent to the player, which is exactly what we want. And now we can add
different values. So e.g. we can put back
the experienced value. So we can do experienced
equal instance dot nu, and this is now going
to be an int value. And then we can see
experienced dot name is then of course, experience. There you go. Then the experienced dot
value is going to be zeros. So we're going to start with
zero, which makes sense. Then very important
here at the end. Experience that parent is
then equal to liters stats. So we then want to
parent each one of our variables under
the leader stats. And in theory, we can
just duplicate this or, or copy this and then
change this to e.g. gold as well, right? So then just change all of this to gold. And let's say we start
with something like ten gold. And now we have this. Now this is not
cold yet anywhere, because where do we call this? Well, we're going to say
players dot player added. This is a, an event over
here as you can see, and this is called each time a player is added to the game. And we're going to connect
this to the leaderboard setup. And now every time a new
player joins our game, they're going to be given
the leader stats folder with the int value experience
and the value of gold with zero
experience and ten volt. So that's really cool. Let's just play and
see if this works. And I assure you
that it will work. You can see now counting Joel has zero experience
and ten gold. And if we open the
player over here, we can actually see there's
a leader sets folder. And instead of it you have
the experience and the gold. And basically the
leader board over here always looks for a leader stats folder and then displays this. Now of course what we can't do anymore is we can click this anymore because right now there's nothing in our backpack, so we actually can
actually display this. So let's go back to here and let's get the
experience clicker. And then let's
also get a both of the clickers right here. So the left one
and the right one, and we'll change
this right here. We were changing the value
of the experience in the backpack and now we actually change it in the leader sets. So how does that work? Well, there's a couple of
ways that we can do this. If we don't want
to check anything, we can literally
just say liter stats that gold dot value equal
to plus equal one, e.g. or experienced, I mean,
whatever we want. Let's just do
experience over here, and let's do experience
over here as well. So we can do this. Now we're just gonna do this for the sake of argument, right? So let's just go in
here and we should be able to find that if I do this, you can see that our experience over here increases.
That's pretty cool. But what if, let's say this
is prone to very easy arrows? Because in this case, I do a typo over here. And all of a sudden we're like, I do a type over here
and all of a sudden I click on this and I get
an error because hey, the experience is
not a valid member. I'm like, What the
**** is going on. I miss type this. So there is a little bit of validation here
that you can do. And that is going to be
something like this. So we can e.g. say, Hey, give me the leader stats
for the player over here. So we're going to get the
leader stands as a variable. This will throw no errors even
if there aren't no liters. That's because, well,
it doesn't matter. And then we can do a local and this is very
interesting indeed. So what we can do is we can say experience stat,
and this is crazy. We can say liter stats. And then put in
liters stance colon, find first child, this is a function and this will
search for experience. This might look
absolutely insane. What we'll do then is we'll
say, if experienced that Then, and then we can
actually increase this. And we can use this by
using the experience. That's what we can
say, experienced that, that value is plus equal one. Why is this better than this? Well, first of all, this makes sure that both the
leader sets exists, as well as finding the actual experience over
here with fine first child, it is validated by using the
if statement right here. And the general idea of this
line rate is that this is true and then it returns
whatever is in here, right? So basically we're saying, Hey, is this not null? That's generally
the idea, right? So leader says it's not null. And then we find
this, this child, which is then saved in the
experience that experience, that value plus equals
one is the same as this. So if we were to, just
for the sake of argument, copy this to the red clicker
as well, and we change this. You, we will see that
this will all work. So we go in here and we're
going to click here and you can see the experience
still increases. This is much better
scripting in this case, and it just makes sure
that everything exists. Now what about the output?
This still does not work well, let's go to the experience
clicker over here. And then here, the same
thing applies, right? We can basically just get this. And then instead of
doing the plus equals, we can just say that
we're going to print out the experienced that data
value here in this case. And then we can
actually do as well. We can do an else statement. So if the experience that does not exist for whatever reason, we can just say this player, player has no experience for
the sake of argument, right? And then if we play this
and we were to go in here, here we now have zero
experience, right? And then we can get
this experience up. Now we have six, so now
we have six experience. That all works, right, so that's pretty cool already. Now, we can go even crazier just for
the sake of arguments. So e.g. what we could do
is we could say, well, if you click on this,
we actually want to know whether or not you didn't
have enough gold, right? Maybe it costs gold
to move the thing. So what we can then say
is we can then do this. And then we can also say, also find me the gold, right? And then we can
say the following. If there's not experienced that this will now
be gold star, right? So this is gold stat. Then we can say if gold stat, then we're going to
check what the value is. If gold stat and gold-standard data
value is more than one, because we're going
to decrease it. Then we can continue
with this and we can increase the
experienced value. And we're going to decrease
the gold standard value. So now we're going absolutely
madness over here. Let's just copy this over
to the other one as well, like I've already
previously mentioned. Now, there is a better
way of doing it. Instead of having two
scripts like this, you can just have
one script and do the same onClick function
for both of them. For the time being,
we're just going to keep it like this,
That's going to be fine. But the general idea is
that we're checking, okay, Do we also
have a gold stat? And if we do, it's the value bigger than one or
bigger or equal? Actually, this is what we want. Yes. And if this is the case, then we're checking for
the experience that we're increasing the experience
that in decreasing the gold. And we can also track
over here instead of an, if, we can do an else over here. And we can then actually print
out something like player doesn't have enough gold
for the sake of argument. So if the player
has zero gold or below about zero would be
what they'd probably have. Then it's going to print
out player doesn't have enough gold. So let's
take a look at this. So let's play, and we will be able to see that
if I go on here, right, I've zero
experience at ten gold. I click this. Now I have one experience
and nine gold and I can, I can click the same one. I'm at zero Gold, everything
is still working fine. If I do this now, then all of a sudden, computer
doesn't have enough gold. Now, the thing is
still moved about. What we can do is we can change this to say, Well,
you know what, It only is going to move if the goal is actually
subtracted, right? So we're going to move the
moving of this just to appear. And then all of a
sudden, we can only move the part if we
actually have gold. Well, that's very
interesting, right? So we can move this about. This is all fine, right? There you go. And we move this one more time, and now I click here
and all of a sudden, nope, doesn't work right? Like you clicked me, but
you don't have enough gold. That's very interesting indeed, that this is some pretty
cool functionality already. To summarize, we use the player added
event for the players to create a leader board folder for each player that
joins our game. And this folder is
going to contain whatever amount of different
variables we want. And they can
represent any type of number or any type of value. Here, in our case, we added experience and gold, and we use this to validate. We need it in certain
number of gold over here to move a part. And then we would get
experienced as well. This is really awesome
and it allows you to, allows you to do so many things. Now, things are really
opening up and we're going to see like way more
things that we can do. But that's gonna be it for
this lecture right here. I hope you found this useful and you'll
learn something new and I'll see you all
in the next lecture. So, yeah.
31. (Roblox) Collectable Parts: All right, let's continue
the Roblox basics here, follow roadblocks course. And in this lecture,
we're going to make parts that you can pick up. So how is this going to look? Well, first of all, let's
just make a new part over here and then let's see. So first of all, we're
going to make this our 333. That is, I think roundabout, the correct size that I want. I want to make them
anchored and I just want to move them up just a
tiny bit of the ground. So we're going to have
something like this. Now we will actually color
them a brighter yellow. So maybe this yellow, I think that that's a
different one from him, right? No, this is new yellow and
this is also new yellow. Let's then do the deep
orange is also fine. So now we have this
port and we're going to call this the gold queue, because this is going to be, well, a gold cube. This is going to have a
new script attached to it, and this is going to be
the gold pickup script. Now we're gonna do this all
over here for the time being. And then I'll show
you how you can make this way, way better. A gold pickup script
for the time being, just to check this
and what do we need? Well, we need to actually know what this particular
gold Cubists, so we need a local gold cube and that's equal to
script dot parent. And then we also need to have a local players and that is
equal to game dot players. Once again, this is the same idea that we are
getting those players. And now we have a local function called on part touched
because we're using the Touched event over
here in just a moment to pick up this particular gold
item or this gold basically, there's several
steps, of course, the first one would be, let's just connect
this gold cubed dot touched colon connect. And then we're going to
put in the part touched over here with no parentheses. So just like this, and now this function or this local
function is going to be called every time that the
Touched event is fired. But we want to only
make sure that this is fired when the
player touches this. So for this one we're gonna
do is we're going to get a, the parent of the other part. So this is gonna be the
other part of that parent. And then we'll get the humanoid
of this humanoid, right? So this is going
to be the parent. So the parent of the
other part, colon, find first child, which
is a and then humanoid. Humanoid. There you go. There's a long function call. Make sure to write
this correctly. So find first-child
which is a exactly written like this in the
same casing as well. And if this exists, then we can do if
humanoid then and now everything inside of here
will only ever be executed. If the other part that
touches this gold cube is going to be a player that has a humanoid
attached to it. So the first thing
we'll do is we'll do gold queue colon destroy, meaning that will
destroy this gold cube. In just a moment. We will actually see that we can do this in a little bit
of a different way. But for the time
being, we'll just do this and then we can
do the same thing that we've done in the
clicker here already, right? So we're basically doing Leary exactly all of this, right? So we'll get the player stats, so we'll say local layer. First of all, we actually
need to get the player. So for this, we need
to do players colon, get player from character because we've talked about
this from character. And we put in the
hair and over here, we put in the parent over here, because let's think about this. We need the player right
now from the players, but we only have access to the character via the
parent over here. Because the character is the thing that actually
touched right? This is the 3D representation of the model and actually
touch the other part. And we need to get
the player from this. This is the way to do it. Then we'll get the leader stats. So liters that's equal to player dot liter sets leader
stats. There you go. And then once again,
we'll get the gold stats, in this case gold star
equal to liters stats. And this is exact same thing
that we've seen here so far. We're just going to
get the leader stats, colon, find first child. And the first trial
that we want to find is gold in this case, if gold stats is true, gold stat is true. This one. There you go. Then what we wanna do
is we then want to, well, not the name,
but then there you go. We want to say gold star dot
value is plus equals one. With this, we have now
a gold pickup port, so we have one of
those right here. So that's pretty cool. Let's just play this and see if I can actually pick this up. But I'm pretty sure that I
should be able to do this. So if I walk towards
it and touch it, the cube is going to disappear and I'm
going to get one gold. And there you go, the cube
has disappeared and I have gained 1 v. Now the
cube is gone forever. And in theory, we could
just duplicate it, Control D, and we can duplicate it and add some more cubes. But at some point you do get
an issue, Let's say e.g. you know, actually, all of those cubes are actually
going to get you to gold. Okay, well, let's change it. Well, wait a second. This has changed it in
one of those, right? This has changed
this particular one, but this one is not changed and this script isn't changed, and the others are
also not changed. That's kind of a bit of a right, that's not too good. So what could we do
to mitigate this? There's a couple
of options that we have at our disposal
to mitigate this. One of them would be to
use a module script. Let's just say for
the sake of argument, create a module
script over here, and we'll call this,
that is 17 dash. And this would be
the gold pickup. Let's just call it like
that. There you go. And then what we could do
is we could just say, well, let's just take pretty much
almost the entirety of this and let's just see what we're going to get as
a function, right? So we're going to make
a function over here. And we're going to call this
module dot goal pickup. And we'll see what kind of parameters we're
going to need. So we need the other part. So this is gonna be
the first parameter. And then we also
need the gold cube, that's gonna be the
second parameter. And the last one is
gonna be the players. That's going to be
the third parameter. And now this should in
theory work question mark. Well, I mean let's
just see, right, so we're going to be able
to do a two over here, and then we just need
to require this so we can say local pickup, Let's say equals require. And then we want
to say game dots, sort of a script
service and then a bracket in quotation
marks 17 and gold pickup. You can autocomplete
with the Tab key. And now we should
be able to call pickup dark gold pickup, passing the other part
as the first parameter, pass in the gold cube as second one and then the
players as the third one. And now, not only is this a
little bit easier to read, write, and we can
always go into this. You can actually, you can hold Control and click on this and then you're going to
actually be brought into this function over here. So that's pretty cool. And now we have this inside
of this particular part. So that's pretty awesome. Now we would still once again
need to change all of them. But if we had this one was
the one that we changed. Yes. So let's just for
the sake of argument, delete the rest and if we
now duplicate this, right? So now we have once
again a couple of those, so we have four of those, but now they all call
the gold pickup one. Well, now if I want
to change the value, they're going to change
floor or the night. If I now change the value
in this module script, they're going to change
for all of them. So if I were to play this right, and we were to go in here, we were to pick this one up. All of a sudden, I get
six gold and I get six gold for this one and this
one and this one as well. So now what happened is
that the gold actually, because they all share the
same function right here, they can all use this one. That's pretty cool because
otherwise we would just be using the
same function anyway. There's no real reason
not to change it. Now this is very cool and
straightforward already. However, let's just say for the sake of argument
in the goal pickup, I'm now going to be
like, you know what? Instead of having the gold stat like this, like the increase, I actually want to just do a
increase variable over here. And I'm going to
put this in here so that I can basically
change, okay? A goal pickup can actually
have different values. Now we're going to
run into the issue of this be nil, right? And then if I play this for the time being, nothing's
going to happen. However, as soon as I then
pick one of those up, it's going to be
like it's gonna be nil because it's not defined. And now we're right
back to the same issue. If I change it here to a
two, that's gonna be fine. But now I have a bunch of other ones where this
is not the case. So obviously what
you want to have at the end here is somehow all of your gold cubes
having one script instead of each one of them having their own script right? Now the way that we
can achieve this is let's just
select all of them, right-click and we're going
to group as a folder. This is going to move up
to the top over here. I'm going to call this the
gold pickups. There you go. And then I will also drop the script inside of the
folder here as well. This is not strictly necessary, but it's just a
little bit nicer. Now we're going to change this
gold pickups a little bit. So right now we
don't have one cube. Write the script here is
actually now the parent. So this is going to
be the pickup folder. Let's say, right, there you go. And what we're going to now
do is we want to iterate through all of the children
of this particular folder. So this is a for-loop now, so this is going to be four. And then what we
can do is we can do an I and an pickup over here in, and this is going
to be an i pairs. So what this does,
you can actually see, it actually says returns
an iterator function and the table for use for loop. So now you might be like what
the **** is going on here. Don't worry, just
give it a moment. So we're just going to use
this for the following, and we're going to use this
for the pickup folder, colon get children. So this is going to get all
of the children, right? That's fine. And then we're
gonna do something. What are we going to do here? First of all, we're
going to say, if I is equal to one, then I want you to continue because that's going to be
the gold pickup script. Okay, that's fair. Then
I want you to do is pick up that touched colon connect. And then I want to
use on-board touched. Okay, I wanna do this
first and foremost. Now, it makes more sense, rather than doing it like
this to literally just take this function over here
and put it inside of here. Because now the
issue becomes that you are going to, we're not
going to name this now. So we're just going to
have a function over here that's going to call this, because the accessing of the gold cube and the players
is a little bit harder. So we're going to move
the players up here, and we'll still need
to pick up over here. And we also need the gold cube. However, we have the gold cube
that has just now pickup. So this is an unfortunate
doubling over here. So this is the pickup script.
Let's call it like that. There you go. And
then the pickup is actually the gold cube. And then we don't
need either of this. And I went through this
maybe a little bit quick. So let's just go through from
the top to bottom again. So I have a pickup
folder, right? This is going to be
this photo that's now called for I accidentally
call this forward. This is called pickups. Take us. There you go, Right? Because we're gonna
do script dot parent, which is the script
parent, okay? And then we have
the players, this is still remains to
be these players. And then we have the
pickup script over here, which is the require for this. Now if we look at this,
we can actually reduce the complexity of this
even more by just saying, by just cutting this out. Because, why do we pass
in the players over here? We could just say,
Hey, you need to get the players. And
then there you go. We've got the players. We can do this and it has access
to the players. So you can see that like this, we're separating out
certain things from certain scripts to
number one make them a little bit
easier to read. And number two, to reduce
the things that we need to do in order to continue working on this
particular game, right? Because let's imagine
we're having. If we have like a
giant field of, I don't know however many
gold cubes over here, right? Having each one of them have their separate script and we need to change
it for all of them. That's all ridiculous. That is crazy. This is why one gold script would be
awesome if this all works. Now, in this case, all of them are going to have
the same number over here. And even that we could change, Let's keep it at two right now. And let's just see what happens
if we were to run this. So the first thing
is going to see we don't have go
pick up, go pickup. That is probably
because we're actually looking at this is
at 11 over here. So the issue is that right now, it actually does try to use it for the gold pickup
script over here, which is actually
kind of interesting. I would've expected
the eye to say, Hey, this is the gold pick
up, then don't do it. This moment when it's actually a zero. That will be interesting. But I don't think
it is. No, it's still, it's still
gonna be there. Okay? Alright, so the I equals
one has not worked. So let's just do
the following them. Just say if pick-up dot name
is equal to gold pick up, then we want to continue. Now this in theory should actually jump over it,
and indeed it does. So there's no more
errors right here. And if we were to run
into this 2222, Let's go. So now you can see, even though the actual
pickups, right, the gold cubes themselves do
not have their own scripts. They're being
destroyed properly. And this is all done
via one script. So this is absolutely
freaking amazing. Right now we could go even
one step further, right? This is now the last step
that we're going to take. And that is, that's
two over here, is still a little
bit weird, right? So you could add another, a value to this
particular gold cube. In theory, we could call
this the gold value, right? So we could call this the gold value for the
sake of argument. And we could call
this to, let's say. And then we could say, hey, when the pickup is done, I actually wanna get the
gold value, dot value. Now it's going to look
for this value over here, and it's going to
read out the value that is written inside
of the gold cube, you get almost the
same issue that you get with the other ones where you have to change it again. So you could also do
something interesting. This is once again, this
is just an example. This is just to get you
to think about this. This isn't necessarily how
you would absolutely do it, but what he could do is also
in can say, You know what? Let's just get the x size and
then make it a dependent, like how much gold
you get, depending on the size of the actual block. So let's say this block
is now two to two. And then we can just delete
a bunch of the cubes. And let's just say
we have a bunch of small cubes and a
bunch of big cubes, and then we have a bunch
of even smaller cubes. So that's gonna be
cubes that are 111. So the, for the sake of
argument here, right? So we're going to have
like a bunch of very, very small cubes and a bunch
of medium-sized cubes. And maybe there's like one
giant cube as like 999, right? Just for the sake of argument. Now the question
is, does this work? Well, I mean, we're
just literally taking the x size of the pickup
port as the value. Why wouldn't this work?
Right? So let's go in here and we'll be able to see if I pick up one of those small ones. We get a one gold. There's two, there's
three gold, right? 311, this is two. That's a two. And there's three again, three again, and this is a
giant one and that's nine. So that is like once again, just to get you thinking about how you can stack
all of the things that we've been talking about so far into one giant thing. Now I will admit this was
a lot of things in here. So I do understand if there's still a little bit confusing, what I recommend you
do is number one, you have the RB Excel file available for download,
so you can download it. Take a look at the script. Number one, the
gold pickup script, and number two,
the module script. See how they work together. Trying to just change
a few things in here. And maybe you can add
some of your own pickups. Maybe as a little bit
of an example that you can add yourself is
maybe you can add, maybe like damaging things
or healing things, right? Healing pickups and
healing healing pickups and hurting pickups or
something like that, just to get a sense of what
is actually happening. But overall, this is
absolutely amazing. So to summarize, we have a pickup that we've made
with the Touched event. We started by
having a script for each one of our cubes
and then went so far as to now have one script over here
that controls the cubes, that basically adds the
Touched event to those cubes. And then one module script where all of the
functionality is in. And this is one of the
highlighted things where a module script is absolutely
amazing for this, right? But that's gonna be it for
this lecture right here. I hope you found this useful and you'll learn something
new and I'll see you all in the next
lecture. So, yeah.
32. (Roblox) Adding Trails to the Player: All right, let's continue
the robots basics here, follow rubrics course. And in this lecture we're
going to take a look at how you can add a
trail to your player. Before we add the trail, what is even a trail? So let's just add it to
my cool part over here. We can just hit the plus n. We're going to search for trail and we're going
to select this. And now it has a trail, right? So now we've added the trail, now we need to add
a two attachments. So in theory to our
cool part over here, we just need to add
two attachments. So let's just do that attachment and then I just duplicated
this with Control D. And we're just going to
move this about two, let's say someone like
this, that's gonna be okay. And then the other
one, we're also going to move to the other side. There you go. And now I can use the first attachment and
the second attachment. And now because it's
attached to this, what we can now do is
when we move this, we should see there you go, a trail appear exactly from that particular
those two attachments. And you can change the trails to do all sorts
of things, right? You can see in the
trail over here, we have we can make it
always face the camera. We even have light emissions. We can give it a texture. There's different
modes that you can do. So static wrap, you can add a transparency to it and then also you can have some
emissions over here. So lifetime maxlength,
you can get the width. So there's a lot of things
and you could also do really cool is you can add a
color in the color here. You can add a color sequence. So e.g. you could just change the color red in the
beginning to read. And then in the
middle here it's like maybe blue and
then you change it over here to a different
green and then over here you change it to another
color so you can get like rainbow colors or all
sorts of crazy things. So you can see now it is
roughly shaped like this. And if we were to now
get this guy moving, so if we move this
now, you can see, now it's changing over time
as pretty cool already. You can see now it's
changing the trail, It's changing its
color linger up with some of the properties. So e.g. or down on the emission, you can add different things
like have more lifetime, so then it's going to
stay alive longer. You can have a minlength and max length and even
adjust the width. So if we were to do like, I don't know, five
year for lifetime, then it's just going to just stay there for way
longer as you can see. Like it's just stays alive
way longer until it decays. So that is pretty cool as well. While it looks cool right here, it doesn't really
do anything for us. So let's add it to the player. The first thing we wanna do is actually in these
servers storage, we want to add a
trail and this is going to be the player trail. So this is going to be the trail that is added to the player. And for the sake
of argument here, let's just change this
to a, once again, a crazy colors over
here. Why not? So let's just go for red
and then a little bit later go to pink and
then we go to blue. And then here we go
to turquoise, ish, let's say, and then green, maybe a little bit later. And then we go to a more
light green and then yellow. And then here at the
end we go to an orange, and then at the very end we
go to the darker red again. So now we have a
cool rainbow color over here, which
is pretty awesome. And we're going to use this
and give it to the player. All of this is fine. Let's then take a look at
this one here, right here. So we're going to make
a max length of this, because otherwise it's going to, I mean, otherwise the
length is infinite and we don't
necessarily want that. And then we're going to
attach this to the player. Well, actually we're going to
attach it to the character, but because the character
is of course the thing that is actually visible, right? That's the, that's
the visible thing that we've gone
through this before. But let's just add a script once again in the
server stub service. And we'll call this 18 dash and we'll call this the
player trail as well. There you go. And let's just zoom
in right here. That's the player trail and
we will make a local players. So this is gonna be our game, game dot players again. And then we want players
dot player at it. So we want to check when the
player has been added and connect this to a particular, connect this to a particular
function here where we get the player and then inside of
here, oh, this is players. Of course, there you go.
Players added, there you go. Then instead of here, we
want to do player dot, character added colon connect, and connect this to
another function, This time getting the character. So we have two events over
here, it inside of each other. This is totally fine and
now we want to continue. So now we want to
clone the trail. So we want to say game
servers, storage, dot, dot player trail, this one, colon clone. So now we've cloned this trail. So we have a credit, a second object of
this particular one. So we literally as if we
were to do control C, control V, And now
we've duplicated it. So that's the general
idea of what clone does. Basically. We then want to say that
the trail Don parent is now equal to the character. Then we want to wait
for about half a second because
this is necessary. What I from what I've
found otherwise, the attachments and things
like that don't quite work. And then we're gonna
make new attachments. So we're going to make
a new attachment. There's gonna be
touched with zero and this equal to an
instance dot new, of course, a new attachment. And we can immediately
say that this is going to go under
Character dot head. So this is going to go to
the head of the character. And then we can say attachments zero dot name is going to be just so that we have this
trail attachment zero. It's not necessary
to change the name, but just to keep
everything organized. And then we can make a second attachment as attachment one. And that is also Instance that new once again and
then a new attachment. And this is two character
that humanoid root part. There you go. And
then we'll change the name of this as well. And this name is
going to be trailed attachment one in this case. And now we still
have to assign this. So we still have to say
Trail dot attachment zero is equal to a tangent zero and trail dot attachment one is equal
to attachment one. Let's just play and let's see what this is going
to come up with. So there we are. And
if I start moving, you can see all of a
sudden we get a really, really awesome trail that follows us well with
a certain length. And we can of course
change this right? If we go to Workspace,
count and jaw. And then down here, we should be able to
find the player trail. And in theory, we could
change this weight so we want to face the camera. So now it's always going to face the camera as you can see, which also looks pretty cool. So you can enable
this on or off. There's light influences. So you can change it here
and just like basically take a look at what this,
what changes over here. So maybe we want to
make this a little bit brighter or maybe woman,
like you know what? No, it's actually going
to be a zero brightness, then all of a sudden it's
completely dark of course. So there's a bunch of
things that you can do here and change it to suit
your needs basically. And this can add a cape
to your character array. This could be something that you want to add for
your characters. Maybe you want to add this to your game so people
can buy this, e.g. with roadblocks as
an example here. But that is the general
idea of a trail. So just for the sake of
argument of additive to the left foot and the right
foot of the character. And let's just see
how that one looks. It's going to look a
little crazy, but why not? You can see it still works. So you get a trail basically
where the character steps. And that's actually
also really cool. I can, I can imagine maybe this for a pet or
something like that. Like a really rare
pet that could have one of those trails that will look really,
really awesome. But yeah, this is a
trail and this is how you add it to
specifically the character. But honestly, you can add
it to mean anything really. So to summarize, a trail can be added with two
different attachments. Now in our case, we're
actually cloning it from the server storage
and then adding it to the character via
two attachments that we're also creating within
a script in this case. And this is not only
doable for a character, you could in theory also
add this to Kaslow. Think that move
different models. You can really do it anywhere where you
have two attachments. Robot, that's gonna be it
for this lecture right here. I hope you found this useful and you'll
learn something new and I'll see you all
in the next lecture. So, yeah.
33. (Roblox) Three Types of GUIs: Alright, let's continue
with the Roblox basics here for the robots course. And in this lecture
we're going to take a brief overview
look into Greece. Greece or GUIs are basically
graphical user interfaces. And they allow the user to interact with a well a
graphical user interface. And there are basically
two different types. We can either
create something in the standard GUI right here, or we can also create
something in the world. Let's start in the standard GUI. And if we press the
plus button over here, you can see it already
suggests to us the screen GUI and that is exactly what we
wanted to create. So we're going to
create a screen GUI. And under this we
can do another plus. And then you could
see we can add certainly UI objects, e.g. a. Frame. And you will see that at
the top left corner here. Now we get a white frame
and we can even move this, so we can move this around. You can see we get
some guiding lines. This is the horizontal middle, and then we can even get it into the exact center of the screen. We can then resize this so we can re-size it
like this, right? So that is pretty cool.
So we can basically just resize this as a lot of things. Even get some guiding
lines where it's at, like how many pixels it is big and how many pixels it
is from the top, e.g. and then inside of this, Let's just actually
increase the size here a little bit more. And then what we can do, right when we center it
again, there you go. We can actually add stuff
to this frame as well. So we can e.g. add a text label and now we've added a label. We can send her this as well. We can maybe size this up a
little bit and we can e.g. say, okay, we want to change the text that is
displayed in the label. We can click on this
label and then go down all the way to
the texts over here, you can see not only can we
change the style of the text, making it bold and
maybe even cursive, right? We can do a lot of stuff. We can make a rich text label
and we can change the text. So e.g. we can say this is
an example of a text, right? And if I send this, there you go, bam, done. We can change the text
size. I want those bigger. Let's make this a
little bit bigger. 32, absolutely amazing. We can even make the scale, so then it scales
automatically as you can see. So if I scale this
particular element than its scales automatically,
which is pretty cool. But let's just get
this out of here. And you can change
the texts as well. The texts color as well. So you can see under this
text, there are very, there are a lot of
properties that you can basically change in
order to change this, let's actually also make
this bold y-naught. And then we have a, well a text element right
here. Pretty cool. And you can see there
are some others. So text button, e.g. That's just a button
with a text on it. You can also have a
image button actually. So this will also work in Image button
that will then have an image on it so you can click this button and
certain things happen. We're actually only going
to see a very tiny example here for the text buttons. So this is just going
to be the close button. So we're just going to change
this from button to close. And let's just size
this up as well. Something like maybe, maybe
50 is going to be okay. And then we're going to
also make this ball. There you go. And if I click
this button right now, nothing would happen because
we can just play this right? If I were to play, what's
going to happen is that the GUI is going to pop up because the GYE
always comes up. And while I can
click this button, like nothing happens and
the GY will persist. But of course, right,
this is kind of annoying. So what you could do is
let's just stop this. And if we wanted to
actually disable this, what we can do is we can
just add a local scripts to our text button over here, and then we can add something. So e.g. this is the example
buttons script, right? This is just a button script. Now, this is a local
script because the GUI only relevant
for our client, right? Only for our particular player. We only have to do this
on the local client. So let's get the button. The button itself is to script dot parent because of course, we're referencing
this script and it's referencing now this
button as the parent. And then we can get the
actual panel as well. So there's going to be the
panel and that is equal to the button, that parent, right? So this would be the frame itself as would be the
frameless call it frame. And if we wanted to
go one step further and actually go to
the screen GUI, we can then say
frame dot parent. So those are all
three that we have. And when we actually
wanted to do something, well, the button
offers us an event. Of course, this would be the button dot
activate, activated. Actually, there you go. So
this is an event over here, lets the activated
event right here. And we can do colon
connect and then just make a new
function over here. And we're getting
nothing actually inside of it or we don't
need to get anything. And then we can just say e.g. print button clicked over
here just to have this. And then we can just
also say screen. So there's gonna be our
screen dot enabled is equal to false and this will basically disable the screen. That is pretty cool. Let's just see if this already works, but it should already work. So let's just go in
and you can see, if I now click on this close, you can see buttonClicked
and also the GUI has now been disabled
because they started, we're right here at this
one has basically been disabled now it's
not been disabled right here in historically, because the GUI is
of course also saved somewhere over here in the
workspace or somewhere else, probably somewhere else,
but it's replicated. And that is the general idea. That is why it is then disabled for our
player. Pretty cool. So that will be one
example of a GUI. Now, one important
thing to note, if you want to, e.g. have an image, right? So if we want to add an image label here
and just center it, you want to change this
image to something else. The issue is going to be that you actually can't really
change it to anything. So right now, our game is
not published onto Roblox. This is deliberate,
and this is why we actually can add a custom
image here right now. As of this time, as soon
as we publish our game. Then we can actually access the ability to also add images, and then we can actually
also add an image here. So do keep this in mind.
We're going to keep it like this for the time being. And we'll actually
go to the screen GUI and enable, disable it. And then we're going to
see the two other GUIs. So there's another type of GUI. Let's just say we
want to add this to, let's say this particular
block over here, the clicker. And what we can do
is we could just do a plus over here and
we can type in GUI, and you can see we
can add a billboard GUI as well as a surface GUI. Let's first of all
add a surface GUI and let's actually take
a look at what this is. So I think there's only clicker. We can now add certain
t