How To Make A Roblox Game – 2019 Beginner Tutorial

In this video I’ll be showing you how to create your own sword fight game on Roblox. So you can fight other players,
be the last one standing, earn rewards and much more that will help you learn how to script.

Now make sure you watch all this video, you don’t wanna miss any of it ’cause I’m gonna be teaching you how you can make your first
game on Roblox with scripting and you’ll be able to publish it and even potentially earn Robux so you don’t wanna miss out on that.

If you’re new to my channel make sure to subscribe and click on the notification bell (bell ringing) so you never miss out when
I upload a brand new video. To start off with what we’re gonna do is we’re gonna go and click on “Baseplate”. And this is gonna create a blank space where we can start making our sword fight game. So wait for it to load and
then what we’re gonna do is just click this tutorials away. And we also don’t need this game window. The two windows that we
are gonna need though actually the three windows
that we’re gonna need is the explorer which is over here, we’re gonna need the properties tab and we’re also gonna need the output. And we don’t need the toolbox yet but we might be using it later on. So let’s just go ahead
and make this full screen. And we can begin by
firstly creating a lobby for the players to stand in
when the game isn’t running or if they get kicked out. So I’m just gonna scale
down the baseplate. And I’m gonna do this quite quickly ’cause it’s quite simple
making the baseplate. And it doesn’t have to be too good so we’re just gonna go into the baseplate and we’re gonna change
the top surface to smooth. And we can change the material as well. I’m just gonna change mine to pebble and we’ll make it green. Okay so there’s my lobby I’m
just gonna rename the baseplate to lobbybase and what I’m gonna do is I’m gonna insert a spawn
location on to this base. And what we’re gonna do
is double-click the spawn to get rid of this decal. And then we’re gonna make the
spawn location transparent and we’re gonna set anchored to true and make sure CanCollide is false. So that the players can walk through it it doesn’t look like a brick
which they will stand on. So what we’re gonna do is we’re gonna find the spawn location and we’re just gonna
duplicate it a couple of times and place them around the lobby so there are lots of
different places to spawn. And once we’ve done that you can just group everything together
in the explorer tab by clicking on the first
one, holding down shift and clicking on the last item. Then you’re gonna press control and G or command G if you’re on a Mac. And we’re gonna call this lobby. So if we go and spawn into the game we should land on our green lobby. Let’s wait for it and there we go, we spawned on one of our spawns and there we go that’s the lobby complete. Next thing that we’re gonna need to do is we’re gonna need to make a map for the players to fight on. So because this is a sword fight game we will do two maps and
then we’ll be able to script so that the game will
randomly choose one map out of the two each round. So let’s get started
by making a desert map. So we’re inserting a part
I’m just gonna make it quite long and quite wide as well so that there’s enough
space to walk around in. We change the color first
to a light, pale yellow. And then we’re gonna change the material to let’s have a look, we’ll do sand. And let’s go and add some walls so the player can’t fall off the map. We’re just gonna make them
quite simple, drag them along. (computer mouse clicking) Woops. We’ll drag that again. (computer mouse clicking)
(bell ringing) Just over here. And then we’re gonna
just scale the wall up so that they can’t jump over it. And then we’re gonna duplicate it with control D or command D. I’m gonna drag it over to the other side. Like this. Here we go. And then we’re just gonna
take both of these walls, select them, duplicate them again. Let’s just turn off collisions so that they don’t spawn on top. So we’ve made a duplicate
and now I’m pressing control R to rotate them. So now we have our border
walls surrounding the map. What we want to do is we
want to change the name to border wall, in fact let’s
just select all of the walls apart from the base and
call them border wall. We’re gonna set transparency to one, make sure they’re anchored
and we’re also gonna set CanCollide to true so that the players they can’t basically walk through them. Okay, let’s just move this wall back because it’s not at the edge of the base. Like that and let’s just
check the other wall. Make sure that that is
at the edge of the base. There we go. Let’s do this a little bit
more, there we go, oops. (computer mouse clicking) Okay so we’ve got the walls all in place. So we can suck them again and make sure transparency is set to one. Woops we don’t wanna do that to the base, we wanna keep the base transparency zero. But now if we go and click play here and we spawn in our map
we shouldn’t be able to fall off the edge. Okay, we didn’t spawn on the
map, let’s try that again. Clicking play here and I
know the base is not anchored so we need to anchor the base and so it doesn’t fall of the
map and we can stand on it. So anchored just means that it’s locked and it won’t fall down. So here we go, we’re in our
map and let’s just go and walk to the edge of the map
and try and jump off. And you can see we can’t walk off, we’re restricted by the
walls that we just made. Okay, so that is the map, let’s just go into the
toolbox and add some cacti from free models, you can build
them yourself if you want. You can make your map look
much better than mine, I’m just gonna insert some cacti. (squeaking) And we can also get rid
of this little plant. So we just want this
cactus let’s just make sure there’s nothing bad in
side of these parts. Nope they all look good. So I’m gonna take the cactus
and we’re just gonna duplicate and move them around the map. Okay there we go. So what I’m gonna do is I’m
just gonna select the floor and change the name to
floor so we know what it is. Then I’m gonna select
everything on our map and I’m gonna go press
control G or command G on a Mac to group all together. And we’re gonna call this desert map. Now we just need to add
some spawns into this map. So it’s not gonna be a spawn location because a spawn location puts you back on that spawn when you reset. But we want to put our players on a spawn in the map when the game’s starting. So we’re gonna insert some basic parts and later on we’ll use these to teleport the player onto the map. So we’re gonna just create our part, we’re just gonna part name to spawn part or let’s call it SpawnPoint. We’re gonna make sure it’s anchored, we’re gonna set CanCollide to false so that they can walk through it. And we’re gonna set transparency to one. Now what we can do is do
the same as we did earlier and duplicate the spawns,
and move them around the map. You wanna make sure you have
enough spawns for all players in your game to be teleported
to a different one. ’cause you done want
people to be teleported to the same spawn ’cause then
there would be spawn kill. And you also want it to be random so you don’t know where
you’re gonna spawn next. So I’ve added a few
SpawnPoints into my game. I’ve got let’s see, two, four,
six, eight, 11, we’ve got 11. So I’m gonna just select
all of my SpawnPoints. Press control G and I’m gonna
call this model SpawnPoints. (typing on keyboard) Remember I’m calling it
SpawnPoints with a capital S and P so make sure that yours is
exactly the same as mine. And then what we’re gonna do is we’re gonna take
these SpawnPoints model and we’re just gonna drag
it inside our desert map. So each map needs to have
a model called SpawnPoints and inside that model there’s going to be lots of SpawnPoint parts where the player could be teleported to. If you don’t have SpawnPoints in your map it’s not going to work. So now that we’ve got our
first map what we’re gonna do is drag it into ServerStorage and we’re gonna create a folder in ServerStorage called maps. So just click on the plus, type in folder, press enter and name this maps. Then we’re gonna drag our
desert map into that folder and I know we said we’ll be doing two maps but we’ll just do one for now, and if it works we might
add a second one later on. So now that we’ve got our maps in there we just need to do one last
thing and insert a sword. Now to keep this series short I’m going to use a
sword created by Roblox. Now you can find this by
typing sword in the toolbox and finding one but
most of them don’t work and some of them are outdated. So what I’ll do is I’ll put a link to the model for this
sword in the description. You can take it and then go to my models and you’ll be able to insert it. So I’m just gonna copy it
in and I’m gonna paste it. Now this is the sword that
we’re going to be using. I’m gonna take this sword and I’m gonna drag it into ServerStorage. Now that we’ve done that what
we can do is we can begin by creating a leaderboard for our players. So let’s go to server script service, click on script and then we’re
gonna name the script, stats. So what we want to do here is
we want to create an event. An event will listen out
for something to happen and when that specific thing happens it will fire some code in a function. So what we want to do is we want to wait until someone’s joined the game. So game.Players.PlayerAdded:Connect
(function[] and drop a line. Now I just need to say your code needs to look exactly like mine ’cause if it doesn’t then
the script isn’t gonna work because this is scripting language. Lua is really picky and if
you spell something wrong or forget to have a capital letter then it’s gonna throw
an error in the output. So if you see an error
make sure to double-check your script against mine ’cause you’ve probably made a mistake. So this is gonna run any code inside of it when someone joins the game. Now we want to have a
parameter here of player. This player here, this word player, we’re talking about the player
that’s gonna enter the game so any player that enters
the game, whatever we do to this player instance
here we’re gonna do to the player that joins the game. So if we give player 100
cash, we’re gonna give every player that joins
the game a 100 cash. So what we want to do is we
want to create some leaderstats so to create a leaderboard at
the top right of our screen we have to create a folder called leaderstats in the player. So we can say local leaderstats equals instance dot new folder like this. Leaderstats dot name equals leaderstats. Now leaderstats has to be in lowercase or else the leaderboard won’t pop up. And we’re just gonna parent
this leaderstats folder (typing on keyboard) so that it lives inside
of the players object. So each player will have their own folder called leaderstats. Now inside of that
folder were gonna create a currency called cash,
so we can say local, well you can call it whatever you want, you could call it cash, you
could call it bucks, coins. Actually let’s go and call it bucks because that sounds quite cool. So local bucks equals and it’s gonna be an IntValue
’cause it’s an integer so a whole number and
then we’re gonna say, bucks.Name equals bucks. And we can set the value
of bucks for now to zero. So any player that joins the game will start off with zero bucks. Now in the future I’m
gonna do a video on how to save your currency and
we’re gonna be giving them a default value when they join so maybe 50 cash when they join. But if they’ve already got saved
data we will load that data so make sure that you are subscribed and you’ve liked the video so
that you’re ready for that. So what we need to do now is parent the bucks to the leaderstats. So any currency value
inside of leaderstats is gonna show up on the leaderboard. So let’s go ahead and play our game again and see if we have some leaderstats. So there you go, you
can see in the top right we’ve got our leaderboard and it’s counting the currency bucks. And you can see in our player we’ve got a folder called leaderstats and inside of that folder we’ve got bucks. Now if we change the name
of our bucks to points you can see nothing updates. Now that’s because we set in the script for it to be called bucks and
you won’t see that change. But if we change the
value of bucks to say 500 you can see that we now have 500 bucks. So we can change the value
of bucks and that will update but if we change the name
of the actual IntValue it’s not gonna update on the leaderboard. So we’ve got our bucks
working perfectly fine and what we can do now is begin scripting our sword fight game. So what we’re gonna do,
we’re gonna click on the plus in server script service again and we’re gonna insert a script and we’re gonna call
this script main script. So this is where we’re gonna
do all the game coding, all of the logic to see if someone’s won, or someone’s killed someone, that’s all gonna happen here. So the first thing we need to do is we need to create some variables. So we’re gonna start off
by creating a variable in fact let’s do little comment. So a comment basically lets you know, you can write what’s happening and the script will ignore it so just a comment for yourself. So define variables, so a
variable just holds data. In this case we’re gonna
hold the path to a service so we don’t have to keep saying
the name to get to that path so local ReplicatedStorage to begin with equals game:GetService ReplicatedStorage. Now what’s ReplicatedStorage
and what’s it used for? So ReplicatedStorage,
anything inside of it gets replicated to the player so that it can be seen by
all the players in the game and it can be seen by the server which is where the scripts run. So inside of there we’re gonna
gave things like the status, status value which we’ll use
to update the GUI at the top which usually says intermission
or something like that. And so that’s where that’s gonna go. We’re also gonna need the ServerStorage and as you’ve seen already, ServerStorage is where the sword goes and also where the maps are. And that’s only visible to the server so any players won’t be able to see that so that they can’t exploit the game. So game GetService
ServerStorage like that. We’re also just gonna create
a variable for our MapsFolder. So we can say local MapsFolder
equals ServerStorage and then we need to
wait in case that folder hasn’t been loaded into the game yet so in case the script is running before the folder has been added. So we can say colon
WaitForChild and that will wait until that folder’s into the game. So we can just say maps
because that’s the name of the folder over here. We’re then gonna wanna create a variable which is for our status value. Now we haven’t added that yet so let’s go ahead and do that now. So we’re gonna go into ReplicatedStorage and insert a string value and this string value is
gonna be called status. Now you might have seen in some games that you have a nice, little banner at the top of your game and it gives you information about the
game usually it will say intermission when a new
game is about to load, it might show you how long’s left. So our main script,
there’s gonna be a value in ReplicatedStorage
which all players can see and this value we’re gonna
update it in the main script and all players in the
game are gonna have a GUI on their screen which will listen out to see if that value’s been
updated with new information. And if it has it will
relay that information to all the players. You’ll see how this works
later on but for now we’re just gonna insert this value and we’re gonna update
it in the main script and then later on we’re
gonna design our GUI and make it so that it picks up the information from this value. So go back into the main script here and what we’re gonna do
is we’re gonna create our status value now that
we’ve added the value in. So local Status equals ReplicatedStorage and once again it might
not be in the game yet so we have to say colon
WaitForChild status. Now because these
scripts run straight away when the game server is created so there might be a bit
of lag or something. And so we need to make sure
all the objects in our game are loaded in before we
start running the game. Last variable for now, we’re
just gonna call it GameLength. So this is in seconds, how long you want each game to last for. I’m gonna set mine to 50 seconds. So this is just the
amount of time in a game until all players are wiped
out in case there’s no winner ’cause this is gonna be a last
man standing sort of game, kinda like a battle royale. So last person standing wins but if there’s more than one person left and 50 seconds have passed,
we’re just gonna end the game. So what we’re gonna do now is
we’re gonna do the game loop. So this is just a repetitive loop that will run for ever and ever and ever until the game shuts
down loading up new games when another one’s finished. So we can do a while loop here. So we can say while true
do and drop a few lines and you can see we’ve got this end here. So a while true do loop will
run any code inside of it forever until it either breaks because we’ve told it to break or if the condition at the top which is currently set to true is false. So let’s say it was two
plus two equals four. That would run forever because
two plus two is equal to four but if it was equal to
five this would never run because two plus two is
never gonna be equal to five. So instead of just
setting it to a condition if we want it to run no matter what we can just set it to true. So what we want to do is we want to check to see if there were
enough players in the game. So we can say when it begins we can say waiting for enough players. Now this is what the status is gonna show if not enough players are in the game because we need two or more
players for this game to work else if there’s only
one player in the game they’re always gonna win so we have to wait for enough players. So we’re gonna set the status to this and we’re just gonna repeat this. We’re just gonna repeat this line of code we’re gonna repeat it until
we give it a wait as well. Repeat wait until game.Players.NumPlayers is greater than or equal to two. Now game.Players.NumPlayers so number automatically updates with
number of players in the game and if it’s less than or equal to two then it’s just gonna keep
showing this status value. But if it isn’t, until
it becomes greater than or equal to two we can
do any code after it. In fact let’s just add a wait one in here ’cause it’s not very good
to just have a small wait ’cause a wait is 0.3 seconds. So if we’re running this all the time it’s gonna make the script less efficient. So what we can do now
is set the status value to Intermission because now
that there’s enough players in the game we can have a little delay until the next game begins. And we can do this for about
five seconds, maybe 10 seconds. So now that all players are in the game and we’re ready to go, we
can begin by creating a table and putting all players in
the game at that time into it. So we’re gonna call
this table local players equals and then we can in
fact let’s call it plrs, just a shortened version of players. I’ll pronounce it as
players, this is a table, we’re gonna put all the
players in the game in it because if someone joins
midway through the game, we don’t know if they
were part of the game when it started or they’ve just joined. So that’s why we do this. So we want to loop through
every single player in the game. So to do that we can use a for loop. So for i, player in pairs
(game.Player:GetPlayers with a pair of brackets after that, do. So for each player in the game, if the player’s there
then we want to add them to that table by saying table.insert then give them the name of the
table which can be players. And we want to insert
that player into the table and player is the current player
that we’re looping through so we’re just gonna add
that player into the table. So we’re just going to add
each player into players table and then outside of
here we’re just gonna do a wait two seconds so that the player can see what’s going on and so that everything
doesn’t happen straight away. Now the next thing that
we’re gonna need to do is select a map from the map folder, randomly select one and
then load it into the game. And we’ll do part two
so make sure you click the thumbnail on your screen
now so that you can go and watch the next part in this series. And don’t forget to click
on the Alvin Blox logo to your left on screen
now or below the video so that you subscribe to my channel. And turn on the notification bell so you never miss out on when I upload a new Roblox scripting tutorial.

As found on Youtube

Click Here to Get Free Robux