As well as being able to play games, though, you can also create your own with Roblox’s versatile game engine known as Roblox Studio. Roblox game making is not only fun for all ages, but allows you to easily create pretty much anything that comes to mind – and multiplayer support is built-in already. With its vibrant community and many opportunities, jumping into Roblox game making has never been easier.
Roblox Studio offers a ton of features to help you in the Roblox game making process including:
Well, if you want to create a multiplayer game to play with friends and don’t want to tinker around with networking code and servers – then Roblox Studio is for you. It’s also a great introduction into game development as it strips away all the daunting complexity of other engines.
If you already have experience in other game engines such as Unity, Godot, or Unreal – then Roblox should have a fairly easy onboarding process as well. The structure of the engine is similar to those mentioned, and learning Lua should be easy if you already have experience in C#, C++, GDScript, etc.
Another benefit of Roblox is that the whole experience of creating and playing games is self-contained. You don’t need to host servers, manage distribution platforms, etc. You hit the publish button and your game is out there for potentially millions of people to play. Roblox also facilitates monetization, so if your game becomes popular you could earn some money. So if you are just starting out with game development, or just want less complicated multiplayer development – then definitely give Roblox Studio a go!
There are millions of different games for you to play on Roblox. Here’s a few of the most popular ones.
Here’s the trailer for Arsenal. A multiplayer FPS game in Roblox.
Alright, so you want to make Roblox games – how do you begin? Well, let’s start by downloading the game engine here. Click on the Start Creating button and you can download the software.
Once you’ve logged into Roblox Studio, you should have the program open. Go to the New page and double-click the Baseplate template.
The engine should then open up.
The only thing we have in our game right now is a baseplate (floor) and a spawn location (this is where the players spawn). To move things around, you can click on them to select (you should see a blue outline). Then you can hold down the left mouse button and drag around to move the part.
Now as you create your games, you’ll want to test them out. At the top of the window, you’ll see a row of different tabs. Click on the TEST tab and click on the Play button.
You’re now playing the game! But there’s not much to do here. When you want to stop playing the game and get back to creating, click on the Stop button.
Ok, so you’ve got the game engine open and you know how to play the game. But how about adding in some content? An obstacle course? Combat? Below is a list of tutorials to get you started!
Lua is the programming language we use to script our Roblox games. These tutorials will help you out if you’re totally new to coding.
]]>
You can access the full course here: Explore Roblox Scripting with Lua
In this lesson, we’re going to learn about events in Roblox.
An event allows other objects to get notified about an action that happened in the game. For example, we can be notified of when a player touched a particular object by listening to the Touched event of that object.
To illustrate this, let’s create an object that changes color when the player walks into it.
Add a new part to the game view and rename it to TouchButton. Change its Size to be ‘3, 3, 3‘ in the Properties window, then change the color to red and the material to be Neon (in the Home tab):
Back to the Properties window of our TouchButton part, enable ‘Anchored‘ and disable ‘CanCollide‘ as we want the player to be able to walk through our cube:
Also, move it a bit up with the Move tool (in the Home tab).
Now that we have our button, let’s make it turn green when we touch it.
Create a Script for our TouchButton and call it ‘TouchButton‘ as well.
We start by accessing the part (which is the parent of our script) and connecting to the Touched event. We then pass in a function with the part that touched our button as a parameter. If we press Play and check the console, we’ll see that the message has been printed out multiple times. That happens because our player is made up of several different parts, such as the head, hands, feet, etc.
To make our button change to green, let’s assign it a new color as follows:
Lastly, let’s have a look at an event that gets called when a player joins the game.
Here, we do ‘game.Players‘ to access the Players service (visible in our Explorer window) and then we listen to the PlayerAdded event.
Playing the game, we should see our own name printed along with the message in the Output window.
Hey, everyone. In this lesson, we are going to be looking at events inside of Roblox Studio. So first of all, what is an event?
Well basically, an event is something that allows other objects to get notified, okay? For example, if the player touches a certain object, what we can do is connect to that event, the touched event, and be notified when the player has touched that object, okay?
It’s similar to calling a function, but a lot more versatile and allows us to basically plug in as many things as we want, okay? So, for example, we could have a large field of hundreds of cubes, for example.
And when the player, for example, clicks a button, all those cubes could change to green, okay? That’s what an event would allow us to do. So, what we’re gonna do is go ahead and create ourselves a little button. And what this is gonna do is turn green when we go inside of it, okay?
When we walk into the object, it’s gonna change color. So, for this, I’m just gonna go ahead and create ourselves a part right here. Let’s rename this one to our touch button. (keyboard clacking) I’m going to change this size, where is that, that is over here.
I’m gonna change the size to be, let’s just say, three by three by three. So, that is three by three cube right here. Let’s go ahead change the color to be red by default and we’ll change the material to be neon, so it is glowing.
While we’re at it, let’s also go enable Anchored, and disable CanCollide because we want the player to be able to walk through this object. All right, maybe move it up a tiny bit like so, and there we go. So now, let’s make this object turn green when we touch it.
So, I’m gonna attach to it a script right here. This script, I’m gonna rename it to be touch button, just like with our object. And here we go. So, first things first, we need to get our actual part, okay? The touch button part that we’re going to be checking. So, I’ll create a local variable called parts, which equals script, oops, script.parent.
The script right here, the parent object is going to be the touch button. That is what we are accessing. So, now that we have referenced to this touch button, what we can do is connect the touched event, okay? So, how do we do this?
Well, if we type down part, then put a dot, you’ll see this list pops up with all the various different things we can look at. And if you scroll down, you’ll see that most of them have this blue little cube next to it. This is a property.
If you look into the properties tab on the bottom right, basically, this is all of the fields that we can modify. You know, the name, the color, the opacity, the parent object, the size, the position. But if you scroll down a bit more, you’ll start to see these lightning bolts, okay?
Stuff like child added, changed, touched, touch ended, and these are all events, okay? So, these lightning bolts are events that we can subscribe to or connect to. And we will basically be listening for when these events are called. And when they are called, we’ll be notified, so we can do whatever we want to do with it.
The event we want to do is go down and find touched, okay? Now, touched is an event that every part in Roblox has, okay? Every part in Roblox that can be touched by a player or entered by a player has this touched event. And this touched event gets cold or invoked once a player inters or touches a part, okay?
And what we’re doing here is we are gonna connect to it. So, the single colon connect and inside of the parentheses, here what we need to do is create a new function that is gonna be cold, okay? So we’re gonna create a function here and we need one permanent to be sent over.
And the object that’s gonna be sent to over is going to be the touched part, okay? So basically whatever part touched us, that’s gonna be sent over, in our case, this is going to be the player when the player touches the part, but doesn’t have to be the player.
It could also be a projectile, could be a rolling ball that rolls through this cube. This event is still gonna be invoke. So, when the player, or when anything touches this object, this touched event is gonna invoke. And since we are connected to it, this card is gonna run inside of here.
So what we can do is print to the output and let’s just say, we’ll go, touch button was touched, okay? We can press play and test it out. So, we’ve got our touch button over here, we’ve got changing our color cubes from the previous lessons. Let’s go up to this cube, and if we look in the console, there we go.
A touch button was touched 16 times. And that is because our player is made up of a number of different parts. We’ve got our hands, feet, our legs, our torso our head, our hair. So that’s why it’s being called multiple times, okay? But as you can see, it is detecting when we are touching this cube right here, as you can see, it goes up, it goes up again.
And events are very powerful in this way, as well as these pre-made events that these objects have, you can also go ahead and create your own. Now, in the next lesson, we’ll be going over actually creating, unique and custom events.
But for now, let’s go and change this color to red. So how do we do that? Well, what we’re gonna do is we’re gonna remove this print line of code right here, and we are going to make the color green. So, for that, we can go part.color equals color3.new.
And if you’re a member of color3 requires three different parameters, a red, green and blue value. Now, since we’ve been able to make this color green, we’re gonna give it a zero for the red, for the green, we’re gonna give it a one and a zero for the blue. So this is gonna be an entirely blue or entirely green button, okay?
So that we can save that, press play. And let’s see if it turns green when we touch it. So, let’s go over here, and there we go, it is turned green. So that is how you can use events for these customer or buttons. You could even maybe have checkpoints as well.
So when the player jumps and lands on a platform, you can register, change place team to be linked to that checkpoint. There’s a wide range of different things you could do. Now as well as parts having events, pretty much everything has events inside of Roblox Studio.
For example, we can have an event that gets cold once a player joins the game, or we could have an event that gets cold once a lot is turned on, okay? So let’s have a look at an event that gets cold when a player joins the game.
So to do this, what we need to do is first of all, access our players service right here, which basically manages all of the players in the game. And to get that we can go game.players, then go .playeradded, as you can see right here, it is an event, colon connect, and we need to create a function with a parameter of the player that is joining, okay?
So, game.players accessing this service right here. Then we are looking at the player added event and we are connecting to that event. So when a brand new player joins the game that play added event is gonna be cold, and that means that this card is gonna be ran.
Now, let’s just say, we want to go ahead and print to the console, the player has joined the game, okay? So for that, we could go print and then we could go player.name, add two dots to basically combine this with another string.
And then in quotation marks, we can put a space and go has joined the game. And okay, just like that. So now when we go ahead, press a five to play the game, we should see down here in the output, it says there we go, I have joined the game.
Okay, so we’ve got all this setup, we had to look at events, here. I’m just gonna remove this for nuisance. It’s good to really put code that only relates to that script in that script, so changing the touch button color to green.
In the next lesson, we’ll be looking at creating some custom events and then connecting those events up. So thanks for watching, and I’ll see you all in the next lesson.
Interested in continuing? Check out our all-access plan which includes 250+ courses, guided curriculums, new courses monthly, access to expert course mentors, and more!
]]>You can access the full course here: Explore Roblox Scripting with Lua
In this lesson, we’re going to take a look at arrays inside Roblox.
To start off, create a new Roblox project using the Baseplate template:
In the Explorer window, we see that our workspace basically only holds a baseplate and the spawn location currently:
If we press F5 to enter the play mode, we’ll spawn in the spawn location and go from there:
Unlike the usual variables that can hold one specific value of a certain type (such as numbers, strings, true or false values) or reference objects, arrays are variables that can be seen as a sort of container or a file cabinet. It holds multiple variables within it and we can access each and every one of them as needed.
Let’s create a script to see how it works in practice. To do that, hover your mouse over the ServerScriptService in the Explorer window, then click on the plus symbol that appears next to it and search for Script. Select it and go to the Properties window. Set the script Name to ‘ArrayTester‘:
The way we instantiate a variable in Lua is by typing local to define the scope (in this case, only accessible by this script and not other scripts). We give it a name, then we add an equal sign and attribute it a value:
This would be an example of a normal variable that only stores one single value.
To create an array, we also add in the local keyword, a name, and the equal sign, but then we add the values in between curly braces like so:
Note that they need to be of the same data type, which means that if you have an array of whole numbers such as above then all values in the array must be whole numbers and not decimals or even values that aren’t numbers at all, for instance.
Arrays are very useful for us as we can have an array with the players in our game and thus perform commands or actions upon them all.
In terms of terminology, we have the element and the indexes that make up an array.
The elements are the values of the array (e.g. 5, 10, 15, and 20 are all values of the ‘numbers’ array above). On the other hand, the indexes are the numbers used to identify specific elements inside the array and stand basically for the position of that number in the array.
To print the third element of our numbers array, we do:
In Lua, the indexes start at 1 so ‘numbers[1]’ will return the first element of the numbers array and so on.
You can test it out by clicking ‘Play‘ in the Script Menu tab or pressing F5.
Make sure you are displaying the Output window to be able to check the console. If it’s not visible, you can open it by clicking on ‘Output’ in the View tab:
To stop playing/testing, press Shift + F5.
To alter an element, we access its index and make it equal to a new value.
Let’s change the first element of the array to be 1000:
Here, we shouldn’t see ‘5’ in the console. We should see ‘1000’ instead.
Now, to add an element such as a fifth element to our numbers array we access that index and attribute it some value:
It works similarly with other types of data, like strings for example:
Even parts, scripts, and other objects in Roblox can be put inside an array just like they can be assigned to a normal variable.
Hey, everyone, and welcome. In this lesson, we are gonna begin by looking at arrays inside of Roblox and how it can improve our programming abilities.
So I’ve gone ahead and created a brand new Roblox project right here using the Baseplate template, which just includes a Baseplate right here and a SpawnLocation for us. All right. So if we press F5, it will spawn in on the SpawnLocation and we can pretty much play the game from here.
Okay. So let’s get started with creating some arrays. Now first of all, what is an array? Well, unlike a normal variable, which can hold a specific value, for example, we have variables that can hold numbers, that can hold strings, that can hold true or false values, variables that can reference parts.
Arrays are variables that act sort of like containers, or think of like a filing cabinet. It’s an array that can contain multiple variables within it that we can choose to access. So I think a good example would be to actually create a script and have a look at how it works.
So I’m gonna go over to our ServerScriptService right here, and I’m gonna create a brand new script. And let’s just call this one ArrayTester. Okay. So here inside of our script, what I’m gonna do is show you how we can create some arrays and modify them.
Now first of all, the way we create a variable inside of Lua here inside of Roblox Studio is we type local to define the scope. In our case, local means that this variable is only accessible by this script. And we then specify a name for the variable. Now let’s just say we wanna call this variable num, for number.
And then we can put an equal sign and give it a default value of, let’s just say, five. Now that is how we create a normal variable. We give it a local, we give it a name, and then we give it a default value. So how do we do this with array? Since I said arrays contain multiple different variables, how do we do that?
Well, what we’re gonna do down here is go local, but this time, we’re gonna go numbers. Let’s actually rename this one to number, actually, to make it a bit easier. So we’ve got number, which is five, and numbers, which is going to be an array of various different numbers, okay?
And this is going to equal, and what we need to do is put in two squiggly brackets, like so, and then we can just enter our numbers. So I can go 5, 10, 15, 20, and all the other numbers that you want, okay? You can put really whatever sort of values you want in here. Just make sure that all the values are of the same data type, okay?
So if you’re working with whole numbers, make sure they are all whole numbers and no decimal. So we can’t, for example, have 15.2. That’s not really gonna work. So they all have to be the same type. And that is how we create an array. Now what are arrays useful for? Why do we need this? Why can’t we just create various different variables, for example, num1, num2, num3, so on and so forth?
Well, the benefit of having arrays is that they are very flexible, and especially when tied into software, like Roblox for example, we can get an array of players. So we can get a list of all of the players in game and then enact some commands or actions upon them by just going, “Okay, for all of these players, do this.”
Or we could be looping through a number of different objects. For example, if we have a bunch of lights in our scene and it turns nighttime and we want these lights to turn on, we could have an array that contains all of the lights inside of our game and just have a function that loops through all of those array elements and turns them on.
Now let’s go over a bit of terminology. With arrays here, we have two things. We have an element and we have an index. So first of all, an element is basically a value inside of an array. So this numbers array right here has four elements: 5, 10, 15, and 20. Each of these is known as an element, an element of an array.
And an array is made up of a number of different elements. Now what is an index? Well, an index is basically the number used to identify a specific element within an array. So let’s just say what we want to do is when we play the game, we want to print, for example, the third element of the array to the console. So we can see 15 pop up in chat.
Well, what we can do then is go down here, go print, and we enter in what we want to print. So how do we print the third element of this numbers array? We can’t go numbers, like so. That will print everything.
So what we need to do is after we write down the array, we need to put down two square brackets, like so, and specify the index, and we are gonna go three, because in Lua, the first element of the array has an index of one, then two, then three, then four.
So if we wanna get the third element of the numbers array, we need to give it the index of three. So hopefully, what this line of code here should do is print out the number 15. So let’s press play and see if that happens. If you don’t have the output window here, you can go over to the View tab and just click on Output right here to enable that.
So let’s press F5 and see if it works. All right, and as you can see over here in the console, it says 15. So it’s printing out the correct number. Let’s go Shift + F5 to stop playing. And for example, if you want to print the first element of the array, you’d go numbers[1]. If you wanted to print the fourth element, you’d go numbers[4] and so on and so forth.
Now as well as being able to read the values, like we are doing here, I’m printing them out to the console, we can also change the values. So for example, let’s just say we wanna change the first value of this array and we want to change it to, let’s just say a thousand. So we can go print out the first element of the array here.
And then what we can do is just go numbers[1]. And what we can then do is just like with a normal variable, we can go = 1000, like so. So what we’re doing is we are defining the array here, we are changing the first element of the array to be 1000. and then we are printing that out to the console.
So when we press play, we shouldn’t see five pop in the console, but we should see 1000. So let’s press F5 and see if that works. And as you can see right here, it says 1000. So that’s working just fine. And yeah, you can go along, you can change the various different elements of your array, but what happens if you want to, for example, add more?
Let’s just say you’ve defined your numbers, but down the track, you’re like, “Okay, I wanna add more numbers to this array. How do I do that?” Well, it’s actually quite simple. What you need to do is, first of all, let’s go ahead and not change one to 1000. Instead, what we’re gonna do is we’re gonna go square bracket.
And right now, the max index we can choose is four because there’s one, two, three, four elements in our array. But what if we entered in five instead? We don’t have an element with the index of five. So what that means is we can define a new one. So numbers[5] = 25. And then let’s log that to the console.
So we can print that out in the output down here. And let’s see how that goes. F5. And there we go, 25. So creating new elements inside of our array is pretty easy. We just define a new index for that number and have it equal to a value. So we’ve got all this here, now how about different data types?
So for example, if we’d go down here and create a brand new local array, and let’s just call this one strings. This is gonna be equal to a new array here, and we can have words. For example, we can have Roblox. And make sure to have these inside of quotation marks. We can have Roblox, we can have Studio. Oops.
We can have Studio. We can have Tutorial, for example. And it’s gonna act in the exact same way. So let’s go print and let’s go strings, and we wanna print out, let’s just say we wanna print out Studio, so we’d give it the index of two. Press F5 to play. And we should see, there we go. It says Studio here in the output. So yeah, it works with strings.
It also works with Booleans as well, so true and false values. Pretty much any type of variable that you can create normally can also be inside of an array. That includes parts, that includes players. That includes even scripts, for example. Pretty much anything in Roblox can be put inside of an array, just like it can be put inside of a variable.
All right. So in the next lesson, we are going to be having a look at how we can actually start putting some of our Roblox-related objects inside of arrays and what we can do with that information.
We’ll be looking at putting players in arrays. We’ll even be looking at going through our Workspace and putting specific things inside of an array. So thanks for watching, and I’ll see you all in the next lesson.
Interested in continuing? Check out our all-access plan which includes 250+ courses, guided curriculums, new courses monthly, access to expert course mentors, and more!
]]>You can access the full course here: Intro to Roblox Game Making
In this lesson, we’re going to move our platform up and down.
To start off, we need to access the MovingPlatform as we’ve done in the previous lesson, and store it into a variable:
Next, we’re going to use a TweenService which is a Roblox service we can use to move our object:
When we type in “game” we’re accessing the entire game that we are currently in, and by doing so we can require the TweenService we need.
Following, we’re going to define how we want the movement to be in the TweenInfo:
The first parameter stands for how long it’s going to take to move the platform between two positions, in our case 3 seconds to go from bottom to top.
Secondly, we have the easing style (whether the movement is going to be smooth, linear, or random). By choosing the linear option, we’re stating that the platform will move up and down at the exact same speed.
The third parameter is the easing direction and we choose ‘Out‘ as we want it to move nice and straight along a single direction.
The fourth parameter is the repeat count, which is basically how many times this tween is going to repeat itself. As we want it to repeat for as long as the game is active, we enter “-1“.
The fifth parameter defines if it’s going to be reversing or not. We’re setting it to true as we want it to reverse.
Finally, the last parameter is the delay time. Once it reaches, the platform’s going to wait 0.2 seconds before going back to the start.
We’re then ready to assign the tween to our MovingPlatform part:
Note that we’re using the TweenService we’ve created to connect our part to the TweenInfo we’ve specified above. Lastly, we give it a position to move the platform to which is its current position plus 20 meters up in the air.
Now, we just need to play the tween.
We can see that it is working just as we’ve specified in our script:
Overall, that is how you set up an obstacle course in your Roblox game. You can add in more checkpoints, platforms, and moving platforms as you wish.
In the next lesson, we’ll be going over how to publish our game.
Welcome back everyone. In this lesson we are gonna finally be moving our platform up and down, okay. Now, in terms of how advanced this is gonna be, it’s gonna be quite a bit more advanced than what we’ve done previously, but we’re gonna go step by step and have a look at how it is done, okay.
So, first of all, what we need to do is have our script open right here and I want you to go ahead and delete all of the code that you’ve currently written, if there is anything, okay. So make a nice blank file and we can begin.
So, first of all, what we need to do is access our Parent part, okay, the moving platform, we need to access this. And we went over this in the previous lesson. All we need to do is go script.Parent to access it.
But in this case, we are gonna assign this to a variable, okay, so every time we’re going to access the Parent part, we don’t have to go script.Parent, okay? Because that’s gonna make our code longer than it needs to be. So what I’m gonna do is put this into a variable and I’m going to go local part equals script.Parent.
So now whenever we write down the word part this is basically going to be referencing our script.Parent. So we can go part.position, for example and we can modify the position that way. All right, nice and easy. Next, what we need to do is access something known as a Tween Service.
Now, a tweenService, okay, there’s two words there, Tween and Service. Tweening is basically, in programming and in-game development, the act of basically moving or rotating an object over time, okay. Animating an object to move to one position to another, or rotate to one position, or rotate to another rotation, for example.
And what we’re going to be doing is using tweening in order to move an object up and down, okay. And a service in ROBLOX here is basically something that is on the server-side and it basically allows us to do certain things, okay. For example, we have the player service, we have our team service, we have our chat service, our localized service, sound service.
It’s basically a lot of different services that we can access. And the Tween Service is going to be what allows us to set up these tweens. So I’m going to do is assign it to a variable. I’m going to go local. I’m going to call this one tweenService and this is going to be equal to, game. Now, when we write down game, this is basically accessing the utmost of the hierarchy.
This is accessing the entire game that we’re currently in. We then went to put in a colon and we went to write down, GetService, okay. And GetService requires basically a name for the service. So, game:GetService with a capital G and a capital S, and then inside of the two parentheses we need to give it a string of the service name.
Now, if you put down the two quotation marks, you can see that a list of all these different services pop up and you can see that with ROBLOX there is a very large number of them. Now, the service we need is going to be the tweenService, like so, okay. It should pop up in the list when you’re typing it down.
So you can just hit enter to auto-fill it, like so. And this is going to access the tweenService which is going to allow us to move this object over time. So, then what we need to do is go down to a new line and we are going to create another local variable.
And this variable is going to contain the information about our tween, okay, because we need to define things such as how long is it going to take to move between the two positions, do we want to smooth in? Do we want it to have a repeating action, so does it want to bounce back and forth?
And also what is the delay of when it reaches the end to returning to the start? You know, is it going to wait there for a couple seconds, then keep moving? This is all the things that we need to define in the tween info. So for this, we’re going to go local.
I’m going to call this one, tweenInfo equals TweenInfo, so, capital T, capital I, and then go, .new . And then inside of two parentheses, we need to define some values that we need to basically assign to this tween. The first number is going to be how long is this platform going to take to move from one position to another?
In our case, let’s just say it’s going to take three seconds, okay. So to move from bottom to top, it’s going to take three seconds. So, I’m going to write 3.0 for three seconds, put a comma. And as you can see what pops up is a text basically defining all the properties or the parameters that we need to give it, okay.
Parameters are basically values that we feed into a function, which this is a function. And so we’ve got the time, next we need the easing style. And the easing style is basically, is it going to be smooth? Is it gonna be linear? Is it going to be random, for example. Now we want it to just be moving up and down, you know, as normal.
So we’re going to go, Enum.EasingStyle. and as you can see here, we have a bunch, we have Circular, Cubic, Elastic, Linear, Quad, Quart, Quint. I’m just going to choose Linear, okay. So it’s going to be moving up and down at the exact same speed. We can put another comma now, and we need to find the easing direction, okay. I’m going to go, Enum.EasingDirection.Out.
Okay, we just want it moving nice and straight, along a single direction. Next, we need to find the repeat counts. So how many times is this Tween going to repeat itself? Now we want to repeat itself, you know, for as long as the game is active.
So we can enter in a large number such as 999,000 million, for example, whatever you want. But a much easier way is to add negative one. And this basically means that it’s going to run forever. Okay, another comma. We need to assign a true or false value for if it’s going to be reversing or not. Now we want it to reverse.
So we’re going to add in true and finally another comma and this is going to be the delay time. Okay, so once it reaches the end, how long is it going to wait there before going back to the start? Now let’s say we want it to be 0.2 seconds, okay. So it’s only going to stay there for a fraction of a second and then move back.
So that is our tween information set up, okay. There’s a lot of things here. Next up, what we need to do is assign the actual tween. Okay, we need to actually create this tween because right now we’ve just created basically the data or the information for this tween.
Now what we need to do is basically tell it, okay, we want to you to apply this tween here to this specific part and we want you to move it to this specific position. Okay, let’s do that now. What we’re going to do is we’re going to go, local tween equals tweenService, so we’re accessing this variable right here, we then want to go, :Create and we need to give it a few variables.
First of all, we need to give it the actual part that we want to be tweening, okay. In our case, that’s going to be the script.Parent which we’ve assigned to the part variable here. So we can just enter in part, like so. So that is the thing that we want to be moving. Next, we need to give it a tweenInfo.
So we’ll send over the tweenInfo right here. Then what we want to do is give it a position to move to. Now the position that we want it to move to is basically going to be this part’s existing position, plus, you know, 20 or so meters up in the air. So for this, what we need to do is add in two squiggly brackets, like so.
And what we’re going to do here is just go, {Position = part.Position + Vector3.New and then two more parenthesis and we need to find a vector to add to that position. Now it’s going to be zero on the X 20 on the Y and zero on the Z, okay. So basically what we’re doing here is assigning the position or the tween position, so where we want it to tween to, to basically be our part’s existing position, plus 20 in the air, okay, 20 vertically.
So it’s going to be moving directly up. And then once it reached that, it’s going to move down back to its origin. Okay, and finally, after all of this, we just need to go tween:Play okay, just like that, two parentheses at the end. And that is going to play the tween. So, this is the code right here, okay.
It can be quite confusing, I do understand that but that is how we can tween an object up and down. So, save that, press play, and if we look over at our platform now, we should see that it is moving up and down, which it is. Let’s hop into server mode, and we can see that the platform’s moving up and back down and you can see when it reaches the bottom it waits 0.2 seconds and then moves back up again.
So yeah, as you can see, it’s got the origin position at the bottom, and then it is moving 20 up into the air. Once it reaches that point, it goes back down and it basically just keeps on doing that forever since we did assign the repeat count to be negative one.
Okay, so, that is our moving platform set up and ready to go. You can, of course, add in multiple more if you wish. But yeah, basically that is the obstacle course set up for ROBLOX. You can, of course, add in many more checkpoints, many more different platforms.
But overall, that is how you set up an obstacle course with checkpoints, platforms, and moving platforms, in your ROBLOX game. Now in the next lesson, we are going to be going over how we can actually publish this publicly so we can then play our game. So thanks for watching and I’ll see you all then in the next lesson.
Interested in continuing? Check out our all-access plan which includes 250+ courses, guided curriculums, new courses monthly, access to expert course mentors, and more!
]]>You can access the full course here: Intro to Roblox Game Making
In this lesson, we’ll be taking a look at how to create checkpoints inside our Roblox game.
As of now, we have only one spawn location where the player starts from and get back to if they fall between obstacles. We might want to have multiple different span locations as checkpoints so once the player crosses them and dies, he’ll return to the last checkpoint saved.
We can add that to our game by going over to the Workspace (in the Explorer window), clicking on the plus symbol next to it, and creating a new folder. Call it ‘Checkpoints‘ by renaming it on the Properties window:
Drag and drop the SpawnLocation into the newly created folder.
Rename the SpawnLocation part to ‘Stage1‘ in the Properties window.
Note: It’s important that you name the parts in your game exactly as seen in the lessons!
Now, scroll down in your Explorer window and click on the plus symbol next to the ‘Teams‘ folder to create a brand new Team:
Rename it to ‘Stage1‘ too.
The way this works is that players are going to be put into a team when they reach a certain checkpoint. By default, every player starts off in the ‘Stage1‘ team. Basically, we’re tying the spawn location and each checkpoint to a specific team. This way, when the players of a certain team die, they will respawn at their team’s spawn point.
Select your Stage1 part (under the ‘Checkpoints‘ folder in the Explorer window) and in the Properties window set ‘TeamColor‘ to ‘Lime green‘:
The ‘TeamColor’ property is an identifier for our team. So now Stage1 is identified by the lime green color.
Also, enable ‘AllowTeamChangeOnTouch‘ so that when players land on this spawn location their team will be changed. The ‘Neutral‘ property means that all players can spawn here, which we will leave enabled for our first stage.
Go to your ‘Stage1‘ team and match the lime green color for its ‘TeamColor‘ property:
Now, the first stage of our game (the first spawn part) is assigned to the Stage1 team.
If we enter the Play mode by hitting F5, we’ll see the player is inside Stage1:
To create a second checkpoint, let’s duplicate our Stage1 part by pressing Control + D (or Command + D if you’re on a Mac) and drag it to the other side of our starting point, after our last added obstacle:
Rename it to Stage2. Set its ‘TeamColor‘ to ‘Really red‘ and untick ‘Neutral‘ as we do not want players spawning here by default:
Following, create a new team named Stage2 (make sure the names do match!) Change its ‘TeamColor‘ property to ‘Really red‘ too.
If we play our game, we’ll see our second checkpoint has been added to the list and once we get there if we fall off the edge we’ll be back to Stage2 as expected:
As a challenge, try adding more obstacles now continuing from the second checkpoint we just included and then add another checkpoint (Stage3) at the other end:
Here we have our Stage3 (both part and team) with a brand new color:
Welcome back, everyone. In this lesson, we are going to be looking at how we can create checkpoints inside of our Roblox game. So right now, we just have our one spawn point over here. And basically, when the player spawns here, they can do the obstacle course. If they do fall down to the void here, they will die, and then they’ll respawn on this spawn location right here.
But along our path, we might want multiple different spawn locations as checkpoints. So once the play gets to the end of this obstacle here, maybe there is a platform they can stand on and then continue, so if they die, they will respawn not back at the start here but moreover here where they last stood on a checkpoint. So, how do we do that?
Well, luckily for us, we can do that entirely without coding. That is all built into the engine here. So what we need to do first of all is I’m gonna go to our workspace, and I’m gonna create a brand new folder and call it Checkpoints.
So I’m gonna create the folder here, rename it to Checkpoints, and I’m gonna drag in our spawn location here. And what I’m gonna do is I’m gonna rename this spawn location. So I’m gonna go down to the properties, and I’m gonna find where we have Name, and I’m gonna call this Stage1.
Now, when I’m naming things from now on, it’s very important that you do name it the same thing as well, okay? Because the game identifies Stage1 by its name and its color, but we’ll get into that soon. So we’ve got our first stage right here. Then, what we want to do is we want to go down into where we have the Teams folder, okay?
We have Teams right here. And what we’re gonna do is click on a plus, and I’m going to create a brand new team, okay? You can see it’s got that little soccer ball icon right there. I’m gonna click on it and rename it to be Stage1. Now, the way this is gonna work is basically players are gonna be put into a team when they reach a certain checkpoint.
So by default, every player is going to be in this Stage1 team when they hit this first spawn point. And basically, what that means is we are tying a checkpoint or a spawn location to a specific team. So when the players of a certain team die, they will respawn at their team’s spawn point, which, in our case, is gonna be this one right here.
So how do we connect this team stage to the spawn point here? Well, first of all, let’s select our Stage1 right here. And what we want to do is go down in the Properties window here to where we have TeamColor, okay? And TeamColor is basically going to be an identifier for our team, for this first team, okay?
I’m gonna click on that, and I’m gonna make the first team. Let’s just make this the green color, so lime green. So basically, Stage1 is identified by the lime green color. Let’s also enable AllowTeamChangeOnTouch so when the players land on this spawn location, their team will be changed. And Neutral basically means that anyone can spawn here.
Now, for our first stage, we want this to be Neutral because we want all players to spawn here. So, enable Neutral. Then, down here in our Stage1 team, as you can see, we have our TeamColor again. And basically, we’ve just got to match this TeamColor with whatever the team color was on our Stage1 spawn location.
So click that, assign that to lime green. So now, this checkpoint right here is assigned to Stage1. And watch what happens when I press Play. Okay, I’ll press F5 and wait for that to load up. There we go. And now, as you can see here at the top-right corner, we have Stage1 highlighted. And you can see that I am basically inside Stage1.
Okay, there we go. So, Shift + F5 to stop playing the game. Now, let’s create our second checkpoint. So, how do we do that? Well, I’m gonna select our Stage1 right here, the part, Control + D or Command + D if you’re on a Mac, and I’m gonna move this over here, okay? Maybe move it down a bit as well so it’s in line with the obstacle course.
There we go. So, we’ve got our second stage. So, what do we need to do? Well, I’m gonna go down to where we have the name, and I’m gonna rename it to Stage2. I’m gonna go down to where we have our Teams dropdown. I’m going to disable Neutral, since we don’t want players spawning here by default, and I’m gonna change the TeamColor to a brand new color.
So let’s say I’m gonna change it to really red. So then, what we can do is go down to our Teams. I’m going to create a new team here. I’m gonna call this team, Stage2. Make sure the names do match. And I’m gonna change the TeamColor, of course, to really red. So, save that.
Now what happens is that if I press Play, so we play the game here. If I reach the end stage, as you can see, it’s added to the list here. So what I can do is, let’s complete this obstacle course right here. And as you can see now, my name has moved up to Stage2 right here. So what happens is that when I fall off the edge, I’m not gonna respawn back at the initial checkpoint.
Instead, I’m gonna respawn at the last checkpoint that I stood on, which was Stage2. And as you can see, here I am next to the yellow cylinder, which means I am at the end, and then I can continue on with the further obstacles. So that is how we can set up our stages right here.
And what I want you to do now is, as a bit of a challenge, I want you to go ahead, I want you to add in some more obstacles, so maybe let’s go off to the right or something, and then I want you to add another checkpoint at the end.
So basically, I want you to add in, let’s just say five or so obstacles for the player to jump over and across, and then add in a brand new checkpoint, Stage3 at the other end. So I’ll be right back to see how you done. And there we go. So I’ve added in my obstacles right here, I’ve added in a little cylinder that the player can jump around, and then I’ve added in the third stage.
Now, Stage3, I’ve basically called this object Stage3, and I’ve assigned the color down here of toothpaste. I’ve also created a Stage3 team in the Teams folder called Stage3, and also given it the color toothpaste. Let’s also put these new parts into our Obstacle Parts folder as well to organize it like so.
And if we press Play, we should see that we have the new team added on the top right-hand side. There we go, Stage3. So from here, you can pretty much add in more obstacles as you wish, add in more checkpoints, and pretty much keep going along with creating your obstacle course, okay?
Checkpoints are going to be a very useful thing in your obstacle course game, as players won’t really enjoy it that much if they’re jumping on platforms for five minutes, they fall, and then have to go back to the start. So make sure to add in checkpoints along the way. Thank you for watching.
Interested in continuing? Check out our all-access plan which includes 250+ courses, guided curriculums, new courses monthly, access to expert course mentors, and more!
]]>In addition, thanks to Roblox’s built-in multiplayer features, your game will be ready to be enjoyed by the millions of Roblox players in an instant – something becoming a necessity into today’s game industry!
If you’re ready to master building FPS games right in Roblox, let’s get started!
You can download the complete project here. Unzip the file and double-click RobloxFPS to open it up in Roblox Studio.
Note that this tutorial won’t be going over the basics, so if this is your first time developing in Roblox, I recommend you follow this tutorial first to learn Roblox game making fundamentals.
Let’s start by creating a new Roblox game, using the Baseplate template.
Then in the Toolbox window, let’s look for a warehouse model to act as our lobby. This is the one I’m using.
By default this warehouse doesn’t have collisions, so let’s go inside and add some parts to act as collider walls.
Cover all 4 sides of the inside.
We can then select all of them and…
Let’s also drag in the SpawnLocation object as we want our players spawning inside of the lobby room.
Finally, we can create a folder in the workspace called Lobby, and put all of our lobby related objects in it.
Now let’s create our arena. For this, let’s go over to the Toolbox and look for a “compound”. These normally have walls surrounding it with buildings inside – perfect for an FPS arena. This is the one I’m using.
We can also change the Baseplate to match the compound.
Next, let’s border up all the gaps so players can’t escape. Starting with the door, we can just rotate to close it.
We can do the same thing for the back entrance. Just copy and paste the doors there.
Now players should be blocked in and not able to get out.
Next up, are the spawn points. Go ahead and create a new SpawnLocation object inside of the Workspace and set it up how you like.
Go ahead and copy/paste a lot of them around the arena.
That’s our arena done! Let’s finish it off by creating a new folder called Arena and put all of the objects that relate to it, inside.
The way we’re going to have players spawn in the lobby at the start of the game and in the arena afterwards is going to be done through teams. Players can be assigned a team and spawn locations too. So when a player respawns, they will spawn at their team’s designated ones. Down in the Teams service, create 2 new Teams.
The team color is what will differentiate the 2 teams.
Now let’s select all of our arena spawn locations and…
Then for the single lobby spawn location…
Now that we’ve got the lobby, arena and spawn locations setup, let’s create the game loop. Let’s start by creating a new script inside of the ServerScriptService service and rename it to GameManager.
Then, inside of the ReplicatedStorage service, we’re going to create a few value objects to hold data.
These are going to be used to hold data that we can change and refer to. Now let’s go over to the GameManager script and start with creating some variables.
local LobbyWaitTime = 5 local KillsToWin = game.ReplicatedStorage.KillsToWin local GameActive = game.ReplicatedStorage.GameActive local CurrentTime local GameStatus = game.ReplicatedStorage.GameStatus local LobbySpawn = workspace.Lobby.SpawnLocation local Players = game.Players local LobbyTeam = game.Teams.Lobby local PlayingTeam = game.Teams.Playing
The LobbyTimer function will be called when players return to the lobby to await the next game. It will countdown from LobbyWaitTime, change the GameStatus string value to display the countdown. Then when the countdown is complete, it will set GameActive to true.
local function LobbyTimer () CurrentTime = LobbyWaitTime while GameActive.Value == false do CurrentTime -= 1 GameStatus.Value = "Game starting in... " .. CurrentTime if CurrentTime <= 0 then GameActive.Value = true end wait(1) end end
After this, we want to listen to when our GameActive BoolValue changes. When it does, we will either teleport players to the lobby or arena depending on if it’s true or false.
GameActive.Changed:Connect(function(value) if value == true then -- change all players team and respawn them for i, player in pairs(Players:GetChildren()) do player.Team = PlayingTeam player:LoadCharacter() end GameStatus.Value = "First to ".. KillsToWin.Value .. " kills wins!" elseif value == false then -- change all players team and respawn them for i, player in pairs(Players:GetChildren()) do player.Team = LobbyTeam player:LoadCharacter() end end end)
Now to get things started, let’s call the LobbyTimer function at the end of the script.
LobbyTimer()
If you press play, you should spawn in the lobby and after 5 seconds spawn in the arena.
We’ve got the GameStatus string value setup and changing, but we can’t see what it’s saying in-game. So let’s create some GUI text.
In the StarterGUI service, create a new ScreenGui and inside of that, create a TextLabel. Rename it to GameStatusText.
Let’s now move the text over to the top-center of the screen.
Then under the ScreenGui object, we need to create a new LocalScript. This is a script that runs only on the local player’s computer.
This script is just going to have two variables. One for the text object and the other for the GameActive value. Then we’ll change the text whenever the value of GameStatus has been changed.
local Text = script.Parent.GameStatusText local GameStatus = game.ReplicatedStorage.GameStatus GameStatus.Changed:Connect(function(value) Text.Text = GameStatus.Value end)
Now if you press play, you should see the text counting down and when in the arena, displaying the kills to get.
Right now, you’ll notice that the player is still third-person. To fix this, select the StarterPlayer.
Pressing play, the camera should now be locked in first-person mode.
With our player setup, let’s create our gun. Over in the Toolbox, search for Handgun and we want to find the Working Handgun model. Here’s a link to the asset. Drag that into the game and open it up, we’re going to modify it a bit.
Delete all parts except for…
Now we can create a local script for the gun called GunScript.
Before we write code, let’s go over to the ReplicatedStorage service and create a new RemoteEvent. A remote event can be used to communicate between the client and server. In our case, when the player shoots another player, we’ll be telling that to the server so they can damage them.
Now back to our gun script. Let’s start with some variables.
-- Parts local weapon = script.Parent local camera = workspace.CurrentCamera -- Sound Effects local shootSFX = weapon.Handle["FireSound"] local reloadSFX = weapon.Handle["Reload"] -- Replicated Storage local replicatedStorage = game:GetService("ReplicatedStorage") local damagePlayerEvent = replicatedStorage:WaitForChild("DamagePlayer") -- Damage local Damage = 25 -- Ammo local CurMagAmmo = 12 local MagSize = 12 local ReserveAmmo = 48 local CanShoot = true
Next, we can create the Shoot function which gets called when we press the left mouse button.
function Shoot (mouse) -- play shoot sfx shootSFX:Play() local target = mouse.Target local humanoid = nil CurMagAmmo -= 1 -- get the target HUMANOID if target.Parent:FindFirstChild("Humanoid") then humanoid = target.Parent:FindFirstChild("Humanoid") elseif target.Parent.Parent:FindFirstChild("Humanoid") then humanoid = target.Parent.Parent:FindFirstChild("Humanoid") end -- if we hit a player, damage them if humanoid then local hitPlayer = game.Players:GetPlayerFromCharacter(humanoid.Parent) damagePlayerEvent:FireServer(hitPlayer, Damage) end end
The Reload function gets called when we need to reload our gun. Here’s what it does:
function Reload () CanShoot = false reloadSFX:Play() wait(reloadSFX.TimeLength) CanShoot = true local leftOverAmmo = CurMagAmmo if ReserveAmmo < MagSize then CurMagAmmo = ReserveAmmo else CurMagAmmo = MagSize end ReserveAmmo -= MagSize - leftOverAmmo if ReserveAmmo < 0 then ReserveAmmo = 0 end end
Alright, now how do we connect these functions to actual interactions? When we equip the gun, we’ll attach a new event that gets called when we press the left mouse button. When that happens, we’ll either shoot, reload or do nothing.
weapon.Equipped:Connect(function (mouse) mouse.Button1Down:Connect(function() if CanShoot == true then if CurMagAmmo > 0 then Shoot(mouse) elseif ReserveAmmo > 0 then Reload() end end end) end)
Now let’s test it out. But how do we give the player their gun? Well let’s drag it out of the Workspace and into the StarterPack. This is where we can give the players things when they join the game.
If you press play, you can test it out. After shooting 12 times, you should hear the reload sound.
In order to see our current ammo, we’ll need to create a gui. In the StarterGui, create a new ScreenGui object called AmmoGui and inside of that create a new TextLabel called AmmoText.
Position and setup the ammo text to look like this:
Now we’re not going to keep the gui inside of StarterGui. So let’s drag it over to ReplicatedStorage. This is because we need to clone and destroy it.
Back in the GunScript, let’s create two new variables.
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui") local AmmoText = nil
PlayerGui is the container which holds all player gui at runtime. AmmoText is what we’ll assign when we create the gui.
Just below the variables, let’s create the UpdateAmmoText function. This will simply update the text to display the current ammo.
function UpdateAmmoText () if AmmoText ~= nil then AmmoText.Text = CurMagAmmo .. "/" .. ReserveAmmo end end
Down where we listen to the Equipped event, let’s add in code to create, assign and update the ammo text.
weapon.Equipped:Connect(function (mouse) -- NEW CODE STARTS HERE local guiClone = game.ReplicatedStorage.AmmoGui:Clone() guiClone.Parent = PlayerGui AmmoText = guiClone.AmmoText UpdateAmmoText() -- NEW CODE ENDS HERE mouse.Button1Down:Connect(function() if CanShoot == true then if CurMagAmmo > 0 then Shoot(mouse) elseif ReserveAmmo > 0 then Reload() end end end) end)
Then we need to listen to when the weapon is unequipped and destroy the gui.
weapon.Unequipped:Connect(function() PlayerGui.AmmoGUI:Destroy() end)
Finally, at the end of both the Shoot and Reload functions, we need to call the UpdateAmmoText function to update the text.
UpdateAmmoText()
Now you can press play and test it out!
Here’s the gun script as of this point in the tutorial:
-- Parts local weapon = script.Parent local camera = workspace.CurrentCamera -- Sound Effects local shootSFX = weapon.Handle["FireSound"] local reloadSFX = weapon.Handle["Reload"] -- Replicated Storage local replicatedStorage = game:GetService("ReplicatedStorage") local damagePlayerEvent = replicatedStorage:WaitForChild("DamagePlayer") -- Damage local Damage = 25 -- Ammo local CurMagAmmo = 12 local MagSize = 12 local ReserveAmmo = 48 local CanShoot = true local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui") local AmmoText = nil function UpdateAmmoText () if AmmoText ~= nil then AmmoText.Text = CurMagAmmo .. "/" .. ReserveAmmo end end function Shoot (mouse) -- play shoot sfx shootSFX:Play() local target = mouse.Target local humanoid = nil CurMagAmmo -= 1 -- get the target HUMANOID if target.Parent:FindFirstChild("Humanoid") then humanoid = target.Parent:FindFirstChild("Humanoid") elseif target.Parent.Parent:FindFirstChild("Humanoid") then humanoid = target.Parent.Parent:FindFirstChild("Humanoid") end -- if we hit a player, damage them if humanoid then local hitPlayer = game.Players:GetPlayerFromCharacter(humanoid.Parent) damagePlayerEvent:FireServer(hitPlayer, Damage) end UpdateAmmoText() end function Reload () CanShoot = false reloadSFX:Play() wait(reloadSFX.TimeLength) CanShoot = true local leftOverAmmo = CurMagAmmo if ReserveAmmo < MagSize then CurMagAmmo = ReserveAmmo else CurMagAmmo = MagSize end ReserveAmmo -= MagSize - leftOverAmmo if ReserveAmmo < 0 then ReserveAmmo = 0 end UpdateAmmoText() end weapon.Equipped:Connect(function (mouse) local guiClone = game.ReplicatedStorage.AmmoGui:Clone() guiClone.Parent = PlayerGui AmmoText = guiClone.AmmoText UpdateAmmoText() mouse.Button1Down:Connect(function() if CanShoot == true then if CurMagAmmo > 0 then Shoot(mouse) elseif ReserveAmmo > 0 then Reload() end end end) end) weapon.Unequipped:Connect(function() PlayerGui.AmmoGUI:Destroy() end)
Let’s now create the leaderboard to display kills, deaths, and wins.
In the ServerScriptService, create a new script called Leaderboard.
We also need to create what’s known as a BindableEvent inside of ReplicatedStorage. Call it WinGame.
A bindable event is like a remote event, but instead of being client-server or server-client, a bindable event is just server-server.
Now in our Leaderboard script, let’s begin with some variables.
local GameManager = game.ServerScriptService.GameManager local KillsToWin = game.ReplicatedStorage.KillsToWin local WinGameEvent = game.ReplicatedStorage.WinGame
Then when a new player is added to the game, we can listen for that.
-- create leaderstats when a new player is added game.Players.PlayerAdded:Connect(function(player) end)
Inside of this event, let’s create our leaderstats folder and make it a child of our new player.
local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player
Then as a child of this leaderstats folder, we need to create values for the kills, deaths, wins and attacker (the player who is currently attacking us).
local kills = Instance.new("IntValue") kills.Name = "Kills" kills.Value = 0 kills.Parent = leaderstats local deaths = Instance.new("IntValue") deaths.Name = "Deaths" deaths.Value = 0 deaths.Parent = leaderstats local wins = Instance.new("IntValue") wins.Name = "Wins" wins.Value = 0 wins.Parent = leaderstats local attacker = Instance.new("ObjectValue") attacker.Name = "Attacker" attacker.Value = nil attacker.Parent = player
Next, we need a way of changing these values when a player is killed. Add this code just under where we created our values but still inside of the player added event.
-- change leaderstats when a player dies player.CharacterAdded:Connect(function(character) character:WaitForChild("Humanoid").Died:Connect(function() player.leaderstats.Deaths.Value += 1 -- increase the killer's kills if player.Attacker.Value then local killer = player.Attacker.Value killer.leaderstats.Kills.Value += 1 -- if the killer has enough kills, they win! if killer.leaderstats.Kills.Value == KillsToWin.Value then WinGameEvent:Fire(player.Attacker.Value) end end end) end)
What are we doing here?
Now if we press play, you should see the leaderboard at the top-right.
We’ve already got the DamagePlayer remote event setup and calling in the gun script. Now we need to create a new script inside of ServerScriptService called PlayerDamageManager.
First, let’s get our variables. The replicated storage and damage event.
local replicatedStorage = game:GetService("ReplicatedStorage") local damagePlayerEvent = replicatedStorage:WaitForChild("DamagePlayer")
Then we can listen to when the event has been called on the server. It will send over three values. The attacker, hit player and damage.
damagePlayerEvent.OnServerEvent:Connect(function(attacker, hitPlayer, damage) hitPlayer.Attacker.Value = attacker hitPlayer.Character.Humanoid:TakeDamage(damage) end)
We can test this out with multiple players by going to the Test tab, setting the player number and clicking Start.
You should be able to shoot and kill other players. You can always increase the lobby wait time in the GameManager if the clients aren’t all in the arena.
Let’s go over to the GameManager script. Here, let’s first set the player’s initial team to Lobby once they join the game.
-- called when a player joins the game Players.PlayerAdded:Connect(function(player) player.Team = LobbyTeam end)
Next, we need to create a variable to reference the win game remote event.
local WinGameEvent = game.ReplicatedStorage.WinGame
Now let’s also listen to the WinGame remote event. This gets called once a player reaches a certain amount of kills.
WinGameEvent.Event:Connect(function(winner) -- increase the winner's wins stat winner.leaderstats.Wins.Value += 1 GameActive.Value = false end)
This will increase the winner’s Wins and set GameActive to false. This will teleport players back to the lobby.
Congratulations on completing the tutorial! We just finished creating a Roblox FPS game from scratch – and learned quite a lot while doing so. We covered setting up a lobby and arena, how to make an FPS camera in Roblox, and even made a multiplayer-friendly leaderboard so every player can see where they stand.
From here, though, you can expand upon this game and skills in a lot of ways. For this project, you could strive to add new mechanics such as health packs, ammo packs, different weapons, etc. Or, if you want to try your hand at something, you can try making a first-person survival game. The sky is the limit with the systems set up here and they can easily be used for other games and genres!
Thank you very much for following along, and I wish you the best of luck with your future Roblox games.
]]>Not only will you learn some nifty tricks to programming with Lua by a professional developer, but with Roblox game making’s soaring popularity, you can this multiplayer game available to millions of players instantly!
Let’s start learning and building our Roblox game project!
You can download the complete .rblx project file here.
Do note that this tutorial will not go over the basics of Roblox Studio. If this is your first time developing with Roblox, you can learn the basics here.
Let’s start by creating a brand new project – using the Baseplate template.
The first thing we’re going to do is set up our lobby area. This is where players will spawn and wait for the game to begin. In the Explorer, select the Baseplate part.
Next, we can setup the spawn location.
We’ve got the baseplate and spawn location setup. Now we need to make it so that players can’t jump off the platform. To do this, we’ll be adding in invisible walls around the baseplate.
Then we can set the Transparency to 1 to make the wall invisible.
Duplicate the wall three times and move/rotate them so they surround the baseplate like so…
Now you can play the game (F5) and make sure that you cannot jump off the baseplate.
To make our workspace a bit cleaner, let’s create a folder called Lobby and store all of our lobby parts in it.
You may also notice that the sky looks a bit weird, this is due to us using the baseplate template. To fix this, open up the Lighting service and delete the Sky. Then re-add it.
Now that we have our lobby, let’s create the arena that the players will be fighting in. This is going to be a separate area from the lobby. Let’s start by creating a new block part for our floor.
Next, we’ll need to create the walls for our arena. This can be whatever you wish. For mine, I went for a colosseum style. Using the modeling tools (union and negate).
Then finally, we can add in obstacles and platforms for the players to move around.
Just like with our lobby, let’s also put the arena into its own folder.
For our arena, we need to create spawn points for players to spawn at. Create a new brick part.
Now we can duplicate and put these spawn points all around the arena. Then create a folder called SpawnPoints in the Arena folder to store them.
Now that we’ve got all of the environments and spawns set up, let’s get the game loop working. It will act like this:
To get this working, we need to create two objects which will contain the game’s state. A BoolValue and a StringValue.
In the Explorer, go over to the ReplicatedStorage service and create those two things (rename them appropriately). ReplicatedStorage is where we can put objects that are stored on the server.
Next, in the ServerScriptService service, create a new script called GameManager.
Let’s start with our variables.
local GameLength = 20 local LobbyWaitLength = 5 local PlayersRequiredToBegin = 1 local LobbySpawn = game.Workspace.Lobby.SpawnLocation local ArenaSpawnPoints = game.Workspace.Arena.SpawnPoints:GetChildren() local GameActive = game.ReplicatedStorage.GameActive local Status = game.ReplicatedStorage.Status
Then we need to create the LobbyTimer function. This runs when all the players are in the lobby, waiting for a new game to start. Here’s what it does…
local function LobbyTimer () while GameActive.Value == false do local players = game.Players:GetChildren() local playerCount = #players if playerCount < PlayersRequiredToBegin then Status.Value = "Waiting for players" else for i = LobbyWaitLength, 1, -1 do Status.Value = "Starting game in... ".. i wait(1) end GameActive.Value = true return end wait(1) end end
We then also have the GameTimer function. This runs when the players are in the arena, giving them a set length of time to play the game, before changing the GameActive value back to false.
local function GameTimer () for i = GameLength, 1, -1 do Status.Value = i .." seconds remaining!" wait(1) end GameActive.Value = false end
Now, this is just counting down, we’re not teleporting the player or anything yet. This is done when we change the GameActive value. We can create this event which gets triggered when GameActive changes to true or false.
GameActive.Changed:Connect(function() end)
If the value is true, then teleport all players into the arena and give them max health.
GameActive.Changed:Connect(function() if GameActive.Value == true then for i, player in pairs(game.Players:GetChildren()) do local character = player.Character character.HumanoidRootPart.CFrame = ArenaSpawnPoints[i].CFrame character.Humanoid.Health = character.Humanoid.MaxHealth end GameTimer() else end)
Otherwise, if it’s false, then we can teleport all players back to the lobby.
GameActive.Changed:Connect(function() if GameActive.Value == true then for i, player in pairs(game.Players:GetChildren()) do local character = player.Character character.HumanoidRootPart.CFrame = ArenaSpawnPoints[i].CFrame character.Humanoid.Health = character.Humanoid.MaxHealth end GameTimer() else for i, player in pairs(game.Players:GetChildren()) do local character = player.Character character.HumanoidRootPart.CFrame = LobbySpawn.CFrame end LobbyTimer() end end)
Finally, at the bottom of the script – we can call the initial LobbyTimer function.
LobbyTimer()
Now you can test it out!
In order to see how much time we have left, let’s create some text on-screen.
In the StarterGui service, create a new ScreenGui object and as a child of that, create a TextLabel.
In our game view, drag the text label to the top-center of the screen.
As a child of ScreenGui, create a new LocalScript. A local script is the same as a script but it only runs on the client – not the server.
All this code will do, is update the text to display the status when the text changes.
local Status = game.ReplicatedStorage.Status local TimerText = script.Parent.StatusText Status.Changed:Connect(function() TimerText.Text = Status.Value end)
Now let’s create the weapon which our players will be using. For the model, we can use the Toolbox window to find one which looks good.
First, open up the sword’s children object and DELETE:
We won’t be needing those. You can then rename the sword to Sword.
Next, drag the sword into ReplicatedStorage as it will be held on the server and given to players when needed by the GameManager script.
After this, open up the SwordScript and delete all the code there – we’ll be creating our own from scratch. First, the variables.
local Tool = script.Parent local CanDamage = false local Damage = 25 local Target
Then we can create the OnTouched function. This gets called when the sword hits another part. We need to first make sure that it’s a player and if so, damage them.
local function OnTouched (otherPart) local humanoid = otherPart.Parent:FindFirstChild("Humanoid") if not humanoid then return end if humanoid.Parent ~= Tool.Parent and CanDamage and Target ~= humanoid then Target = humanoid humanoid:TakeDamage(25) else return end CanDamage = false end
The Attack function gets called when we click our mouse button. This will play a swing animation.
local function Attack () Target = nil local anim = Instance.new("StringValue") anim.Name = "toolanim" anim.Value = "Slash" anim.Parent = Tool CanDamage = true wait(0.5) CanDamage = false end
Then finally, we need to hook these functions up to their respective events.
Tool.Activated:Connect(Attack) Tool.Handle.Touched:Connect(OnTouched)
Here’s the final script.
local Tool = script.Parent local CanDamage = false local Damage = 25 local Target local function OnTouched (otherPart) local humanoid = otherPart.Parent:FindFirstChild("Humanoid") if not humanoid then return end if humanoid.Parent ~= Tool.Parent and CanDamage and Target ~= humanoid then Target = humanoid humanoid:TakeDamage(25) else return end CanDamage = false end local function Attack () Target = nil local anim = Instance.new("StringValue") anim.Name = "toolanim" anim.Value = "Slash" anim.Parent = Tool CanDamage = true wait(0.5) CanDamage = false end Tool.Activated:Connect(Attack) Tool.Handle.Touched:Connect(OnTouched)
We’ve got our weapon, now we need to give it to the players when they spawn in the arena and remove it when back in the lobby.
Let’s go over to the GameManager script and create a variable referencing the weapon.
local Weapon = game.ReplicatedStorage.Sword
Then when the game active value is true, we want to add the weapon to each player’s backpack and equip it.
local tool = Weapon:Clone() tool.Parent = player.Backpack character.Humanoid:EquipTool(tool)
Then when game active is false, remove the weapon.
for _, obj in pairs(character:GetChildren()) do if obj:IsA("Tool") then obj:Destroy() end end
Here’s the GameActive.Changed event with the final code:
GameActive.Changed:Connect(function() -- teleport all players into the ARENA and GIVE them a weapon if GameActive.Value == true then for i, player in pairs(game.Players:GetChildren()) do local character = player.Character character.HumanoidRootPart.CFrame = ArenaSpawnPoints[i].CFrame local tool = Weapon:Clone() tool.Parent = player.Backpack character.Humanoid:EquipTool(tool) character.Humanoid.Health = character.Humanoid.MaxHealth end GameTimer() -- teleport all players into the LOBBY and REMOVE their weapon else for i, player in pairs(game.Players:GetChildren()) do local character = player.Character character.HumanoidRootPart.CFrame = LobbySpawn.CFrame for _, obj in pairs(character:GetChildren()) do if obj:IsA("Tool") then obj:Destroy() end end end LobbyTimer() end end)
We’ve got most of the game setup and working. But there’s no score right now. So how do we do that?
In the ServerScriptService, create a new script called Leaderboard. This is where we’re going to create and manage player kills.
First, let’s get a list of all the players.
local Players = game.Players
Then we can create the SetupLeaderboard function. This will be called when a new player joins the game.
local function SetupLeaderboard (player) end)
Inside of this function, let’s create our leaderstats folder. It’s important that the names are the exact same as the code below, as the game requires specific naming.
local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player
Now with our leaderstats, let’s create a new int value to store our kills.
local kills = Instance.new("IntValue") kills.Name = "Kills" kills.Parent = leaderstats
Then (still inside of the function), let’s run some code when the player’s character has been added.
player.CharacterAdded:Connect(function(character) local humanoid = character:WaitForChild("Humanoid") local objectValue = Instance.new("ObjectValue") objectValue.Name = "Killer" objectValue.Parent = humanoid humanoid.Died:Connect(function() local killer = humanoid:WaitForChild("Killer") if killer then game.Players:GetPlayerFromCharacter(character).leaderstats.Kills.Value += 1 killer = nil end end) end)
Finally, at the bottom of the script, let’s call the SetupLeaderboard function every time a new player joins the game.
Players.PlayerAdded:Connect(SetupLeaderboard)
Here’s the final script.
local Players = game.Players local function SetupLeaderboard (player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local kills = Instance.new("IntValue") kills.Name = "Kills" kills.Parent = leaderstats player.CharacterAdded:Connect(function(character) local humanoid = character:WaitForChild("Humanoid") local objectValue = Instance.new("ObjectValue") objectValue.Name = "Killer" objectValue.Parent = humanoid humanoid.Died:Connect(function() local killer = humanoid:WaitForChild("Killer") if killer then game.Players:GetPlayerFromCharacter(character).leaderstats.Kills.Value += 1 killer = nil end end) end) end Players.PlayerAdded:Connect(SetupLeaderboard)
Now that we have our leaderboard, let’s go back to our weapon script and navigate over to the onTouched function. Just before we take damage (the line above humanoid:TakeDamage(25)), we want to set that player’s Killer value to be us – the attacker.
humanoid:FindFirstChild("Killer").Value = Tool.Parent
Here’s what the full function looks like:
local function OnTouched (otherPart) local humanoid = otherPart.Parent:FindFirstChild("Humanoid") if not humanoid then return end if humanoid.Parent ~= Tool.Parent and CanDamage and Target ~= humanoid then Target = humanoid humanoid:FindFirstChild("Killer").Value = Tool.Parent humanoid:TakeDamage(25) else return end CanDamage = false end
Now we can test our game! To test a multiplayer game, you need multiple clients. Roblox Studio has that feature build in. Over in the Test tab, you can select the number of clients, then click Start.
Once done, just click on the Cleanup button to close the clients and server.
There we go! We now have a fully functional multiplayer arena combat game in Roblox. Over the course of this tutorial, we’ve learned a lot! We set up a level, learned how to manage our spawn points, created a UI, added weapon combat, and more! We even learned how Roblox game making makes it super easy to make our games multiplayer without a lot of complicated coding.
From here, you can expand in a number of ways. If you enjoyed this project, you can try adding in new features such as different weapons, powerups, etc – all common features for battle royale types of games. Or, since we’ve learned a lot about Roblox Studio’s features and Lua, you can use your new knowledge to create a different game all together – whether that be some sort of race car game, pet game, or something else entirely.
Thank you very much for following along, and I wish you the best of luck with your future Roblox games.
]]>You can download the .rbxl file here.
To create games in Roblox, we need to download the game engine: Roblox Studio. Go to https://www.roblox.com/create and click on the Start Creating button. If you don’t already have it installed, it will prompt you to do that.
Once Roblox Studio has been installed, we can open it up. Here, it will prompt you to log in. If you already have a Roblox account you can use that, but if you don’t you’ll have to create one.
This will then take us to where we can create a new game. Click on the New tab and then double-click the Baseplate template to create it. We’re going to be basing our game of this template as it comes premade with a spawn point.
Now we are in the editor. Roblox Studio is comprised of various different windows/panels. We can move them around, resize or remove them if not needed.
What I’m going to do, is go to the View tab at the top of the screen and disable the Toolbox and Terrain Editor windows so they are no longer in our editor. We don’t need these for the tutorial and it will clear our editor up.
Let’s now go over the different windows and what they’re used for.
Right now, the camera is looking at the spawn point, which is sitting on top of our baseplate.
Now let’s start to create our game. Like many other obstacle courses, we can’t have a floor otherwise the players can just run to the end. So we need to delete the baseplate. Over in the Explorer window, open up the Workspace by clicking on the arrow to the left. The Workspace contains all of the objects found in our game that the player can see, interact with, etc.
Select the Baseplate and delete it by clicking the Delete key on your keyboard.
Now we have no floor. But the sky looks a bit weird. Under the Lighting section, delete the Sky object as we need to reset it.
With the sky deleted, hover over Lighting and click on the + icon. A window opens up and this allows us to create a new object to put into the Lighting section. Search for Sky and add that. You should see now that our sky looks like – a real sky.
As we create our game, we’ll want to test it out. To do this, go to the Test tab and click on the Play button (shortcut: F5).
You’ll see your character load in and you can play the game like you would on Roblox. To stop playing, you can click on the Stop button (shortcut: Shift + F5).
You’ll notice that you spawn on the white object. This is our spawn point and all players who join the game will spawn here.
Now let’s look at how we can move things around. In Roblox, all objects with physical properties are known as Parts. We currently have our spawn point, which is a part. You can click on it to select it. Over in the Model tab, we can select the Move tool to move the part around. You’ll see three colored arrows. Click and drag on these to move the object along that axis.
As well as moving objects, we can also Rotate and Scale them.
Let’s now create the obstacle course. In the Model tab, you’ll see the Part button. Click on the little arrow underneath it and select Sphere. This is going to create a new sphere part which we can move over to the left.
Let’s also scale it up.
Now by default, all new parts are not anchored. What this means, is that if we were to play the game now, the sphere would fall into the void. Since we want to jump on it, let’s anchor it. Select the sphere and over in the Properties window, find the Anchored property and enable it.
Now if we press play, you should be able to jump on the sphere.
We can also color the parts to make it look more appealing and less bland. Select the sphere and click on the Color dropdown. Here, we can choose from a range of different colors.
I’m going to choose black, so it stands out.
From here, create a few more spheres, continuously playing the game to make sure that the jumps are possible.
In an obstacle game, you don’t always want players to restart from the beginning when they fall. Placing checkpoints along the way is what we’re going to do next. First though, we need to modify our spawn point.
Then we want to go down to the Teams folder. What we’re going to do is create a team for each checkpoint we have, so when a player dies, they will respawn on their teams checkpoint part. Create a new Team and call it Stage1 (it’s important that it’s named the exact same as the part). Down in the Properties window we also want to change the TeamColor. This has to be the exact same color as the spawn point part (Medium Stone Grey).
To make our checkpoint look cleaner, let’s open it up in the Explorer and delete the Decal object. This is the spiral texture.
For the second checkpoint, we want to duplicate the Stage1 object (select it and click Ctrl + D).
Then down in the Teams folder, we want to create a new team.
For all of the Team objects, do the following:
Now if we press play and reach the second stage, we will respawn there when we die.
We’ve worked on our game for a bit now. How about saving our progress? Well, there are a few ways we can do this. If we click on File at the top-left corner of the screen, you’ll see we can save our game to a file, or to Roblox.
Saving our game to file, will create a .rbxl file and store it somewhere on our computer. Saving our game to Roblox will do the same, but store the game on the Roblox servers so we can access it from any computer. You can choose which way you want to save. If you plan on saving to Roblox, then I recommend you also save to file.
From here, continue to create checkpoints, add in more obstacles and create a fun game! Make sure to test it out along the way as every jump needs to be possible. Another thing: make sure that every new part you create is anchored. If you notice that some parts are missing or falling when you press play, then this may be the issue.
Let’s add some moving platforms to our obstacle course. These will be moving up and down and will require the player to time their jumps. I’m going to create a new part and call it MovingPlatform. Position it where you want the lowest possible point for the platform to move from. Make sure to also anchor this part!
Then, we’re going to hover over the part, click on the + and add in a new Script. What’s a script? Basically it’s a file where we can write code. This code can then apply logic to the game. In our case, we want this code to move the platform up and down.
Roblox uses Lua as its programming language. If this is your first time ever coding, do know that we’re not going into detail on each element – rather focusing on just the things we need. If you are familiar with programming, then Lua may be easy to get the hang of if you have Python experience.
You’ll notice by default, this script file has one line of code.
print("Hello world!")
This will basically log the message “Hello world!” to the console when we play the game.
What we’re going to do, is delete this line and start from a blank file.
To begin we need to get the part that this script is attached to (the MovingPlatform part). To do this, we’re going to add in this line of code. It is creating a variable (piece of data we can reference) called part and assigning it to the script’s parent, which is the MovingPlatform part.
local part = script.Parent
Then we need to access the tween service. This basically allows us to create smooth movement.
local tweenService = game:GetService("TweenService")
Next, we need to create a new tween. This tween will contain the information of how we want to move the platform. Duration, easing style, easing direction, number of times (-1 means forever), whether it reverses or not and the wait time.
local tweenInfo = TweenInfo.new(3.0, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, true, 0.2)
When we have multiple platforms, we’ll want them to move at different times. To do this, we can delay the final part of the code by using wait(). Wait basically pauses the script for a set amount of time. In our case, we’re going to be choosing a random wait time between 0 and 4.
wait(math.random(0, 4))
Finally, we need to apply this tween to the part and play it.
local tween = tweenService:Create(part, tweenInfo, {Position = part.Position + Vector3.new(0, 20, 0)}) tween:Play()
Here’s the final set of code.
local part = script.Parent local tweenService = game:GetService("TweenService") local tweenInfo = TweenInfo.new(3.0, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, true, 0.2) wait(math.random(0, 4)) local tween = tweenService:Create(part, tweenInfo, {Position = part.Position + Vector3.new(0, 20, 0)}) tween:Play()
Now we can go back to our baseplate tab and play the game!
You should see the platform move up and down.
Next, we can duplicate the moving platform like so. Also adding in a new checkpoint.
Now when you press play, you should see that the platforms are moving differently from one another.
Right, we’re done! Now it’s time to publish our game on Roblox for all to play. Go to File > Publish to Roblox As… This will open up the publish window. Click on the Create new game… button.
Fill out all the information on the next screen, then click Create.
Next, we need to make it public or for friends only. Go to File > Game Settings… and navigate to the Permissions tab. Here, we can choose who can play our game. I selected Public, then clicked Save to save the changes.
Whenever you make changes you want to publish again, you’ll need to go File > Publish to Roblox.
And there we go! You have successfully created your first game for Roblox. Share the game around and see if other people can beat it!
However, we encourage you to not stop here. Many types of games are popular with Roblox game making, and you can really spread your wings in terms of what you can achieve! We encourage you to learn more about Roblox Studio and what you can do with the engine. Additionally, by learning the Lua scripting language more thorough, you can not only make more complex and unique games, but have skills that go beyond just Roblox. Thank you for following along, and I wish you the best of luck with your future Roblox games.
]]>