Explore Free Roblox Game Making Tutorials – GameDev Academy https://gamedevacademy.org Tutorials on Game Development, Unity, Phaser and HTML5 Fri, 24 Feb 2023 21:14:37 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 https://gamedevacademy.org/wp-content/uploads/2015/09/cropped-GDA_logofinal_2015-h70-32x32.png Explore Free Roblox Game Making Tutorials – GameDev Academy https://gamedevacademy.org 32 32 Roblox Game Making Tutorials – Complete Guide https://gamedevacademy.org/roblox-game-making-tutorials/ Sat, 14 Jan 2023 08:19:57 +0000 https://gamedevacademy.org/?p=13831 Read more]]> Roblox is an online game platform that has been very popular since its release in 2006, and is largely driven by its enthusiastic community. There are thousands of custom-made games that are open for the public to play in a multiplayer setting, ranging from simulations to battle royales.

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.

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Roblox Studio Features

Roblox Studio offers a ton of features to help you in the Roblox game making process including:

  • A large online library of 3D models, textures, images, etc.
  • Use of the Lua programming language to script game logic.
  • Well-documented API information.
  • The ability to instantly publish games online which are immediately ready to be played with friends.

roblox studio editor

Who is this For?

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!

Popular Roblox Games

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.

How to Start with Roblox Studio

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.

roblox create page

Once you’ve logged into Roblox Studio, you should have the program open. Go to the New page and double-click the Baseplate template.

roblox studio template page

The engine should then open up.

roblox studio editor

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.

roblox studio test tab 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.

roblox studio stop playing the game

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!

Roblox Tutorials

Lua Tutorials

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.

Roblox Community Links

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
How to Use Events in Roblox – Lua Scripting Tutorial https://gamedevacademy.org/roblox-events-tutorial/ Fri, 24 Sep 2021 01:00:39 +0000 https://gamedevacademy.org/?p=14653 Read more]]>

You can access the full course here: Explore Roblox Scripting with Lua

Intro to Events

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):

Part TouchButton

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:

Properties Anchored

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.

local Part = script.Parent
Part.Touched:Connect(function(touchedPart)
print(“Touch button was touched”)
end)

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:

local Part = script.Parent
Part.Touched:Connect(function(touchedPart)
Part.Color = Color3.new(0, 1, 0)
end)

Lastly, let’s have a look at an event that gets called when a player joins the game.

game.Players.PlayerAdded:Connect(function(player)
print(player.Name .. ” has joined the game!”)
end)

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.

Transcript

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!

]]>
How to Use Arrays in Roblox – Roblox Scripting Tutorial https://gamedevacademy.org/roblox-arrays-tutorial/ Fri, 17 Sep 2021 01:00:28 +0000 https://gamedevacademy.org/?p=14578 Read more]]>

You can access the full course here: Explore Roblox Scripting with Lua

Intro to Arrays

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:

Baseplate template

In the Explorer window, we see that our workspace basically only holds a baseplate and the spawn location currently:

baseplate spawn location

If we press F5 to enter the play mode, we’ll spawn in the spawn location and go from there:

play mode

What is an Array?

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 ScriptSelect it and go to the Properties window. Set the script Name to ‘ArrayTester‘:

Script properties

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:

local number = 5

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:

local numbers = {5, 10, 15, 20}

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.

The Use of Arrays in Roblox

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:

print(numbers[3])

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:

Output view mode

To stop playing/testing, press Shift + F5.

Altering and Adding Elements to the Array

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:

local numbers = {5, 10, 15, 20}
numbers[1] = 1000
print(numbers[1])

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:

local numbers = {5, 10, 15, 20}
numbers[5] = 25
print(numbers[5])

It works similarly with other types of data, like strings for example:

local strings = {“Roblox”, “Studio”, “Tutorial”}
print(strings[2])

Even parts, scripts, and other objects in Roblox can be put inside an array just like they can be assigned to a normal variable.

Transcript

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!

]]>
How to Create Moving Platforms in Roblox https://gamedevacademy.org/moving-platforms-roblox-tutorial/ Fri, 10 Sep 2021 01:00:05 +0000 https://gamedevacademy.org/?p=14561 Read more]]>

You can access the full course here: Intro to Roblox Game Making

Moving Platform

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:

local part = script.Parent

Using the TweenService

Next, we’re going to use a TweenService which is a Roblox service we can use to move our object:

local part = script.Parent
local tweenService = game:GetService(“TweenService”)

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.

Defining our Tween with a TweenInfo

Following, we’re going to define how we want the movement to be in the TweenInfo:

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)

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.

Assigning the Tween to our MovingPlatform

We’re then ready to assign the tween to our MovingPlatform part:

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)
local tween = tweenService:Create(part, tweenInfo, {Position = part.Position + Vector3.new(0, 20, 0)})
tween:Play()

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:

Moving Platform Play

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.

Transcript

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!

]]>
Roblox Studio Tutorial – Creating Checkpoints https://gamedevacademy.org/roblox-checkpoints-tutorial/ Fri, 03 Sep 2021 01:00:52 +0000 https://gamedevacademy.org/?p=14529 Read more]]>

You can access the full course here: Intro to Roblox Game Making

Checkpoints

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:

Checkpoint Folder Stage1

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:

Checkpoint Team Stage1

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.

Connecting Teams to Checkpoint Parts

Select your Stage1 part (under the ‘Checkpoints‘ folder in the Explorer window) and in the Properties window set ‘TeamColor‘ to ‘Lime green‘:

Checkpoint Folder team connect

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:

Stage1 TeamColor

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:

Stage1 Play

Creating More Checkpoints

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:

Multiple Checkpoints

Rename it to Stage2. Set its ‘TeamColor‘ to ‘Really red‘ and untick ‘Neutral‘ as we do not want players spawning here by default:

Checkpoint Folder Stage2

Following, create a new team named Stage2 (make sure the names do match!) Change its ‘TeamColor‘ property to ‘Really red‘ too.

Checkpoint Team Stage2

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:

Stage2 Play

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:

Obstacles

Here we have our Stage3 (both part and team) with a brand new color:

Obstacle Stage3

Transcript

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!

]]>
How to Create a Roblox FPS Game https://gamedevacademy.org/roblox-fps-tutorial/ Wed, 14 Jul 2021 01:00:52 +0000 https://gamedevacademy.org/?p=14200 Read more]]> With this step-by-step tutorial, you’re going to learn how to create an exciting and action-packed Roblox FPS game complete with lobby, arena, scoreboard, and goal of getting 10 kills per round.

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!

roblox fps game

Project Files

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.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

Creating the Lobby

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.

creating the warehouse model

By default this warehouse doesn’t have collisions, so let’s go inside and add some parts to act as collider walls.

first collider wall

Cover all 4 sides of the inside.

collider walls

We can then select all of them and…

  • Set the Transparency to 1
  • Enable Anchored

Let’s also drag in the SpawnLocation object as we want our players spawning inside of the lobby room.

spawn location in lobby

Finally, we can create a folder in the workspace called Lobby, and put all of our lobby related objects in it.

Roblox Explorer for the Lobby

Creating the Arena

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.

creating the compound

We can also change the Baseplate to match the compound.

  • Set the Material to Sand
  • Set the Color to Bright orange
  • Delete the child Texture object

Roblox Properties Window for Compound Level

Next, let’s border up all the gaps so players can’t escape. Starting with the door, we can just rotate to close it.

Door object added to Roblox compound FPS level

We can do the same thing for the back entrance. Just copy and paste the doors there.

Door rotated to block players in Roblox FPS game

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.

creating the arena spawn

Go ahead and copy/paste a lot of them around the arena.

Top down view of Roblox FPS 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.

Roblox Explorer showing Arena level objects

Teams

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.

  • Lobby, with a TeamColor of White.
  • Playing, with a TeamColor of Lime green.

The team color is what will differentiate the 2 teams.

creating the teams

Now let’s select all of our arena spawn locations and…

  • Disable Neutral
  • Set the TeamColor to Lime green

setting up the arena spawn location teams

Then for the single lobby spawn location…

  • Disable Neutral
  • Set the TeamColor to White

setting the lobby spawn location team

Game Loop

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.

game manager script

Then, inside of the ReplicatedStorage service, we’re going to create a few value objects to hold data.

  • Create a BoolValue and call it GameActive
  • Create a StringValue and call it GameStatus
  • Create an IntValue and call it KillsToWin
    • Set the value to 10.

int values

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.

Game Status GUI

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.

game status text

Let’s now move the text over to the top-center of the screen.

  • Set the BackgroundTransparency to 1
  • Set the TextColor3 to white
  • Set the TextSize to 40

aligning text

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.

ui local script

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.

First-Person Mode

Right now, you’ll notice that the player is still third-person. To fix this, select the StarterPlayer.

  • Set the CameraMode to LockFirstPerson
  • Set the CameraMaxZoomDistance to 0.5

starter player fps

Pressing play, the camera should now be locked in first-person mode.

Creating the Gun

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…

  • The base Handgun tool.
  • The Handle and its sounds.

setting up handgun

Now we can create a local script for the gun called GunScript.

creating gun script

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.

damage player remote event

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:

  1. Disable the ability to shoot.
  2. Play the reload sound and wait for it to finish.
  3. Enable the ability to shoot.
  4. Subtract from the reserve ammo.
  5. Set the current mag ammo.
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.

handgun placement

If you press play, you can test it out. After shooting 12 times, you should hear the reload sound.

Weapon Gui

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.

weapon gui text

Position and setup the ammo text to look like this:

ammo text placement

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.

ammo gui

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)

Leaderstats

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.

win gam remote event

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?

  • When a player dies, increase their Deaths value by 1.
    • Increase their Attacker kills by 1.
    • If the Attacker has the KillsToWin call the win game event with the attacker as the parameter value.

Now if we press play, you should see the leaderboard at the top-right.

Damaging Players

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.

testing the Roblox FPS game

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.

Winning the Game

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.

Conclusion

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.

]]>
How to Create a ROBLOX Action Game: Arena Combat https://gamedevacademy.org/roblox-arena-combat-tutorial/ Wed, 30 Jun 2021 01:00:56 +0000 https://gamedevacademy.org/?p=14019 Read more]]> In this tutorial, we’ll be creating an arena combat game in Roblox – featuring repeating rounds of combat that allows players to increase their score.

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!

complete roblox combat arena game

Project Files

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.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

Creating the Lobby

Let’s start by creating a brand new project – using the Baseplate template.

new roblox studio project

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.

  • Down in the Properties window, let’s change the Scale to 100, 6, 100.
  • I also went ahead and changed the Color to deep orange.

setting up the baseplate in Roblox Studio

Next, we can setup the spawn location.

  • Delete the Decal child part.
  • Select the SpawnLocation and set the Transparency to 1.
  • Disable CanCollide and CanTouch.

fixing the spawn location in Roblox Studio arena combat project

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.

  1. Create a new Block part.
  2. Scale and position it along one side of the baseplate.
  3. Rename it to InvisibleWall.

creating an invisible wall in Roblox Studio arena level

Then we can set the Transparency to 1 to make the wall invisible.

setting the wall transparency to 1 in Roblox Studio

Duplicate the wall three times and move/rotate them so they surround the baseplate like so…

adding in the final invisible walls to Roblox arena combat game project

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.

creating the lobby folder in Roblox Studio Explorer

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.

fixing the sky part in Roblox Studio

Creating the Arena

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.

  • Rename it to Floor.
  • Set the Brick Color to gold.
  • Set the Material to sand.
  • Set the Size to 200, 16, 200.
  • Make sure to also enable Anchored so that the platform doesn’t fall.

arena floor creation in Roblox Studio

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).

creating the arena walls in Roblox studio

Then finally, we can add in obstacles and platforms for the players to move around.

arena obstacles and platforms added in Roblox Studio editor

Just like with our lobby, let’s also put the arena into its own folder.

arena folder in Roblox Studio Explorer

Spawn Points

For our arena, we need to create spawn points for players to spawn at. Create a new brick part.

  • Set the Transparency to 1.
  • Set the Size to 5, 1, 5.

spawn point added in Roblox Studio editor and Explorer

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.

spawn points folder for Roblox Studio arena game project

Game Loop

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:

  1. Players start in the Lobby
  2. After 5 or so seconds, all players will be teleported to the Arena.
  3. After 30 seconds, all players will be teleported back to the Lobby.
  4. Repeat.

To get this working, we need to create two objects which will contain the game’s state. A BoolValue and a StringValue.

  • A bool value can hold a true or false value.
    • We’ll be using this to know if the game’s currently active (players are in arena).
  • A string value can hold a string of text.
    • We’ll be using this to update the current time remaining for all players.

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.

Roblox Studio Explore with the Replicated Storage section circled

Next, in the ServerScriptService service, create a new script called GameManager.

Roblox Studio with the GameManger script selected

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…

  1. As long as the GameActive bool is false:
    1. Wait for the required players to join the game.
    2. When that number is met, countdown.
    3. When the countdown is complete, set the GameActive value to true.
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!

UI

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.

setting up the ui with a TextLabel in Roblox Studio

In our game view, drag the text label to the top-center of the screen.

  • Rename it to StatusText
  • Set the Text to Starting game in… 5

creating the text label and centering it in Roblox Studio

  • Set the BackgroundTransparency to 1.
  • Set the AnchorPoint to 0.5, 1.
  • Set the TextSize to 30.

Changing the text label in Roblox Studio arena project

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.

local script selected in Roblox Studio arena combat game

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)

Creating the Weapon

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.

importing the sword in Roblox Studio

First, open up the sword’s children object and DELETE:

  • ThumbnailCamera
  • MouseIcon

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.

creating the sword script in Roblox Studio Explorer

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)

Equipping the Weapon

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)

giving weapon code as seen in code editor

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

code snippet for for loop in code editor

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)

Leaderstats

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.

leaderboard script in Roblox Studio explorer

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)

Connecting the Weapon to the Leaderboard

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

Testing on Multiple Clients

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.

multiple clients testing option in Roblox Studio

Once done, just click on the Cleanup button to close the clients and server.

Conclusion

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.

]]>
Roblox Game Making: Create Your First Obstacle Course https://gamedevacademy.org/roblox-game-making-platformer-tutorial/ Wed, 16 Jun 2021 01:00:49 +0000 https://gamedevacademy.org/?p=13933 Read more]]> While it’s been around for a while, since 2006 to be specific, Roblox has skyrocketed in popularity in recent years. In turn, interest in Roblox game making has risen as well, and with the Roblox Studio engine, it’s more possible than ever to make your own games. With built-in publishing tools and multiplayer, meaning no networking code or server management on your part, it has also become a top choice for beginning game developers who want to focus on getting fun creations out to the public. How does one get started though? Well, in this tutorial, we’re not only going to show you the foundations of Roblox Studio, but help you start your Roblox game-making journey by building a game in a popular genre – obstacle courses.

Gif demonstration of a Roblox obstacle course

Project Files

You can download the .rbxl file here.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

Installing Roblox Studio

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.

Screenshot of the Roblox Studio website

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.

roblox studio login screen

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.

Roblox Studio templates with Baseplate selected

Editor Overview

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.

Roblox Studio Editor for a blank project

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.

Roblox Studio editor with various windows disabled

Let’s now go over the different windows and what they’re used for.

  • At the top of the screen, we have our main Toolbar. This is where we can change our tools, create models, play the game, change settings etc. It’s fairly general purpose.
  • On the left, we have the Toolbox. This is where we can import models and textures that other people have made and put them into our game.
  • On the right, we have the Explorer. This is a hierarchy of all the objects and parts in our game. As well as the services we can use.
  • Below that is the Properties window. When we select an object in the game, we can modify its properties and settings in this window.
  • Finally, in the center is our viewport into the game. This is a camera we can fly around and build our game.

Navigating the Game View

Right now, the camera is looking at the spawn point, which is sitting on top of our baseplate.

  • Holding down Right Mouse and moving the mouse around will rotate the camera.
  • While doing that, you can use the WASD keys to fly around.
  • and Q can be used to move up and down.

Let’s Begin!

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.

Roblox Studio with the baseplate being deleted

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.

Roblox Studio with the Sky selected for deletion

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.

Roblox Studio with Lighting selected in the Explorer

Testing the Game

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).

Roblox Studio with the Text view open and play button circled

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: ShiftF5).

Playing a game in Roblox Studio

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.

Moving Objects Around

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.

Moving parts with the Move tool in Roblox Studio

As well as moving objects, we can also Rotate and Scale them.

Rotating objects in Roblox Studio with the Rotate tool

Creating Our Obstacles

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.

Roblox Studio with a Sphere created in the project

Let’s also scale it up.

Scaling the sphere in Roblox Studio with the Scale tool

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.

Anchoring the sphere in Roblox Studio

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.

Roblox Studio with the Color Picker options window open

I’m going to choose black, so it stands out.

Roblox Studio with the sphere colored black

From here, create a few more spheres, continuously playing the game to make sure that the jumps are possible.

Creating multiple spheres in Roblox Studio project

Checkpoints

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.

  1. Hover over Workspace, click on the + and create a new Folder.
  2. With the folder selected, go to the Properties window and change the Name property to Checkpoints, this will rename the folder.
  3. Rename the spawn point the Stage1, using the same method as above.
  4. Then click and drag the Stage1 object in the Explorer over the Checkpoints folder to add it.

Checkpoints folder add to the Roblox Studio project

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).

Stage 1 team in Roblox Studio

To make our checkpoint look cleaner, let’s open it up in the Explorer and delete the Decal object. This is the spiral texture.

Deleting the decal in Roblox Studio project

For the second checkpoint, we want to duplicate the Stage1 object (select it and click Ctrl + D).

  1. Move it over to the other side of the spheres.
  2. Rename it to Stage2.
  3. Change the color to red.

Creating stage 2 in Roblox Studio platformer project

Then down in the Teams folder, we want to create a new team.

  1. Rename it to Stage2.
  2. Change the TeamColor to the exact same as the stage 2 part color.

Creating team stage 2 in Roblox Studio project

For all of the Team objects, do the following:

  1. Enable AllowTeamChangeOnTouch.
  2. Disable Neutral.
  3. Set the TeamColor to that stage’s respective color (must be the exact same as that’s how the checkpoints are identified).

Roblox Studio Explorer and Properties for Stages

Now if we press play and reach the second stage, we will respawn there when we die.

Saving the Game

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.

Roblox save to file options

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.

Continuing the Obstacle Course

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.

Roblox obstacle course level lay out

Moving Platforms

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!

Roblox Studio process for moving platforms

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 studio with Script file open

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.

Blank script file for Roblox Studio project

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!

Going back to the baseplate game in Roblox Studio

You should see the platform move up and down.

Moving platform up and down in Roblox Studio

Next, we can duplicate the moving platform like so. Also adding in a new checkpoint.

Multiple moving platforms and final checkpoint in Roblox Studio obstacle course project

Now when you press play, you should see that the platforms are moving differently from one another.

Playtesting Roblox obstacle course for moving platforms

Publishing Your Game

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.

Publish window for Roblox Sutdio with "Create new game..." selected.

Fill out all the information on the next screen, then click Create.

Basic Info window for Roblox Studio game

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.

Permissions options with Public circled for Roblox Studio game

Whenever you make changes you want to publish again, you’ll need to go File > Publish to Roblox.

Conclusion

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.

]]>