How To Make A Story Game On Roblox - Episode 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so welcome to the tutorial on how to build the story game now before we begin just remember that if you would like to get full access to the finished project so you'll have all of the code written and the game will be functional and you'll just be able to take it and without having to copy any of the code from this tutorial you can become a channel member and you'll need to become a premium member to do that you can click on the join button which is below this video next the subscribe button and it just is a great way to support the channel and as well as that like i said you get access to the source code from the video but if you don't want that don't worry you can just follow along copy the code as i do but just a quick word from me if the game doesn't work for some reason if the code that you've written isn't working and it's not like mine then what you should do is try to debug it because most of the time i get people telling me that it doesn't work but actually it does and they've just made a mistake when they've copied out the code so i'd say 99 of the time if it doesn't work for you it's because you've done something wrong you've copied it wrong you've forgotten to add a line of code that i did for example you've made a typo etc and a lot of the time you it's hard to notice these things so you could be looking over your code for a while you could be like oh it's not working it's not working and not realize that it's actually you that has done something wrong so i'm just outlining that at the start if you do whilst you're watching this tutorial at any point if you do find out or realize that your code isn't working that your game isn't working like mine don't worry pause it have a look through try to make sure see you've not done anything stupid like a typo or something but there are places you can go to get help you can use the roblox dev forum it's a great place to upload your code and to ask for help if it's not working just make sure to explain what's not working in detail and there'll be people who will help you without further ado let's get into the tutorial so we're going to click on the base plate template here and just load into a simple base plate and i'm going to go into the workspace over here and i'm going to click on the base plate click on the spawn location in the explorer panel and just delete it okay now i'm going to do is i'm going to use the kit so i've created a kit which will insert all of the important things you need for your story game so we're just going to skip the building of the lobby and the map because you might want to build your lobby a different in a different way you might want to make it look different to mine and since everybody's might be different we're just going to use a pre-made kit which i've created in advance that you can use for free to just give us a bit of a kick start get us a bit of a head start on the tutorial so that we don't have to waste time with the building when the thing that matters is the coding right we want to make sure that the code is in there and then once the game's completed you can go on and then change uh your your lobby your map etc so i'm going to click on the toolbox and we're going gonna click on uh well actually you need to get the model first so i'll leave a link to the description where you'll find a link to the model so if you click on that link and then just click on get or take just make sure that you you you buy or access the model it's free and that will just put it into your toolbox so once you've gone ahead and done that go to your uh your model section click on this little icon here and then it should be here look story game kit and then i'm going to click on that and it will insert everything we need for the lobby into our game so i'm going to just close down the toolbox here and what we've got is we've got the little spawn area over here we've got the two lanes for our trucks and then we've got a dark zone and this is where the trucks will will move into and it'll get darker and darker and then we will teleport them so what we need to do first is just move some of these assets around because they're not in the right place so we're going to take the exit gui now this is the thing that will show up on the screen when you get in a truck because you might want to actually get out of the truck before it leaves so we give the player an option to do that so if we take this exit gui and we just drop it into the starter gui here okay so once it's in the starter gui we're just going to leave it there and then the two remote events here called leave truck and show exit gui we're going to select those and we're going to just drag them into the replicated storage down here okay so we've got the grass spawn area and truck lanes in the workspace anything that's in the workspace uh can be seen in the viewport here so we can see our trucks we can see our grass we can see the spawn area etc so that's everything we need now once we've done that we need to start coding these trucks because they won't do anything for now so we need to make it so that when you walk up to the truck you sit in it and you might be able to see here that if we go into the let's see we go into the if you press alt here press down alt or option if you're on a mac and you hover over you can see that there's a part here and this is like a wall and when we touch this wall we are going to put the user into the truck so we've got we've got a wall for each side and we're going to create some scripts we're going to write some code which will detect when you touch one of these walls and when you do that we're going to put the user uh into the truck and they will sit in the truck here and then this will count down from 30 seconds i know it says 10 seconds but we can change that and when it gets to zero the truck is going to move all the way down here into the dark zone and then we will teleport the users so not too much uh coding will be used in this episode it's going to be fairly short and then we'll be able to move on to creating the story so let's get started so if we go and click on those walls again by pressing alt or option on a mac you'll see that we've got lane one detector in the lane one model inside the truck lanes and we've got lane two detector now both of these have scripts inside of them called detector script and i've written these already just to speed things up so we can move on to coding the truck but i just wanted to explain what this does because i want to make sure you're understanding the code i want to make sure that you know you're learning how to become a roblox developer because this stuff is quite important so this script is inside a part and that means that we can say script dot parents so the parent is the thing that the script is inside so in this case we're talking about the lane one detector when we say script dot parents and since the lane one detector is a part it has some events and this is a touched event so a touched event will trigger when a player touches the part so when the player goes up close to the wall and touches it then we are connecting that event trigger to this function and a function is just some pre-written code that we can run at a certain point so we are running this code when a player or an object touches the lane one detector but the problem is anything could touch the lane one detector it doesn't have to be a player it could be the truck might accidentally touch it or um you know another part might touch the lane one detector and that's obviously not a player so we only want to put the player in the truck if they are a player we don't want to go and put um let's say for example we don't want to put this sign in the tr in the truck if it accidentally touches this wall because it's quite close to it or if something accidentally falls from the sky or you know you get the idea right so we are just checking to make sure that the hit the thing that hits the lane detector is stored in within this function it's called an argument so this hit you can kind of think of it as like a substitute so if we were to substitute the hit with the actual part that touches the brick because we don't know what is going to touch this lane one detector so we're just using this hit argument as like a just like it was something that we can substitute in later to be the actual thing that touches it so anything that we do to the hit will be done to any object that touches our lane one detector so we're just calling a function in in the game.player service called get player from character and we're using the parents of the thing that hit the brick because the thing that's going to touch it if it's a player it's going to be one of their body parts so it could be their left arm their right arm their right leg their left leg for example so and you can actually see if we play the game you'll see that in your roblox character which spawns in the explorer you'll see that you've got a left foot left hand left lower arm so when you touch this detector brick it's not going to be your player that touches it it's going to be one of your body parts so it could be your left lower arm your left lower leg so if my left arm touched that invisible part then the hit would be my left arm it wouldn't be my player and the the body parts are inside of my character model so the parent of that body part will be my character model so we're just doing a check here to make sure that there is actually a player uh attributed to my character and this will either be true or false so this function which is a built-in function to roblox it's already pre-coded by roblox it just allows us to do a simple check to see if there is a player linked to this character or this model so for example if a part like that sign touched it then its parent would be the model of the sign probably so it would probably be this sign model here and this function would just tell you that no that is not a player so it would return false and then we're just storing that in a variable for now so that we can reference it later on a variable is just a a piece of data piece of information that can be stored under a name like plr or player that's what it's short for and that will hold the true or false value so if it is a player then this if statement is going to run it's going to execute any code inside of it so if the player is true so if player then is the same thing as saying if the player variable is equal to true so if it is true then we're going to find them a seat on our truck and to do that we are going to say script dot parent dot parent so you can see the script here the first parent is the lane one detector the second parent is the thing that the lane one detector is inside of and the lane one detector is inside of a model called lane one you can see if we collapse and expand you can see it's inside of it and then the parent of that lane one is the truck lanes right so inside of the truck lanes sorry no if we it would be lane one because we're going back one step two step so look detective script is where we start off the script we go back a step to the parent which is laying on the detector and then we go back another step to the parent of that which is the lane one and inside the lane one which is the equivalent of script or parent apparent we have a truck and inside this truck you can see here this is the truck inside this truck we have another model called seats and inside the seats model we have a load of seats here and what we can do is we can go to our detector scripts and we say colon get children so we are just getting all of these seats here and we're adding them to a table a table is just a set of data or a set of objects that we can loop through so we're going to loop through all of those truck seats and we're going to put the player into the seat if it's not already occupied so v is each individual seat that we look through so it would be this seat then v would be the next one and the next one and the next one and the next one and the next one until it's looped through every single seat so for every single seat in the truck we're checking to make sure it's not already occupied because each seat has a property called occupied oh sorry occupant so it's going to be the object of the player that's sitting in it so we can say if not veda occupant and that's the same thing as saying if there is no occupant of the seat then it's empty and we only want to put them in the seat if it's empty so this if statement will only run if the seat is empty and then we can call a function on the seat called sit and then we just put the character's humanoid in there the humanoid is an object attributed to the sorry inside the player's character which um gives them the ability to walk and move and it makes them a player pretty much and so what we can do is we can specify that players humanoid the player who touched the brick and that will sit them in the seat and then we're going to set their jump power to be zero that's a property of their humanoid again another thing that just makes the player work and act like a player it has a property called jump power and if that's set to zero it means that they can't press the space bar and jump out instead we want to show that gui which will let them click exit and then if they do click on that then they will be teleported back to the spawn area so we're just firing a remote event to that player which will enable that gui to appear and we'll talk more about that in a little bit but then we just break out of this for loop because we found a seat for them all that this for loop did was just loop through each seat until we found one that wasn't occupied now it could be that all of the seats are empty and the first one that we looped through was not occupied and we didn't have to go through any more or it could have been that we looped through every single one until we got to the end and the last one was was empty so we could put them in that one so that's what we're using the loop for but if we go and play the game you'll see that uh if we roll up to one of these detectors over here and you can see it sits us in the seat and the leaf button appears on the screen and if we click on the leave button uh nothing happens right now but that is because we haven't coded it yet so let's go ahead and look at the code for that now now if we go into the started gui and we look at our exit gui you can see you've got the exit button and there's a property of that called visible and that's what makes the gui appear or not now all we're going to focus on is this client exit button because i've already put this in the gui and i've written some code which will make it appear when that show exit gui remote events is fired that's what we fired from our detector script here we're picking it up in our local script and we're making the exit button visible now i also have another event for when you click on the exit button so when the exit button gets clicked we're connecting it to another function and the code that will run when you click on this button is it will make the button invisible again but it will also fire the remote event called leave truck we haven't coded that remote event on the server yet so nothing's happening when we're firing this event but we want to pick up this remote event and when a player does fire this leaf truck remote event on the server we can teleport them back to the spawn area so what i'm going to do is i'm going to click on the plus next to server script service and i'm going to insert a script i want to call this script leave truck okay so call it leave truck and put it in the server script service now all we're going to do is we're going to say game dot replicated storage dot leave truck dot on server event colon connect and then inside of these brackets we're gonna write function we're gonna then put another pair of brackets like this we're gonna drop a line and we should just have this end with a closing bracket added on here and then inside of these brackets next to function we can put player because this is going to be the player who fires the remote event so it gives us another reference to them we don't know who it's going to be but we can use this player argument so that anything we do to the player within this script will be done to any player who fires the event and we just want to check to make sure that the player is still in the game so if player then we can say player colon load character like this okay so we do a player colon load character and then a pair of brackets because this is calling a function and this function will respawn the player and it will put them back on a spawn point okay so let's play the game again and see the changes that we've made so we're going to walk over to our truck we get placed into the seat we click on leave and our player gets respawned so we're now out of the truck okay and again boom you see how it works so next we need to make our trucks move because currently the sign is counting down but when it gets down to zero nothing's happening and also i'll walk through the code for the signs as well only one of them is working at the moment but don't worry we'll make both of them work i'll just give you an overview of the code so if we go into our truck lanes over here and we click on lane two and we click on the truck you'll see that there is a script within this truck and this is the script which is going to make the countdown on the sign the reserving of the server for the story game and making the truck move it that's what's going to control all of this now it's only in the truck on the right side okay that's why the sign on the right side was counting down but the one on the left wasn't and that's fine we can duplicate this script and put it into the other truck and once you've gone through it but i just wanted to explain line by line what's going on in this script so firstly let's just focus on this wild true do loop so a while true do loop will run any code inside of it forever and ever and ever as long as the condition in the middle is true so it could be a check such as while two plus two is equal to four or while uh my variable is equal to true whatever but if we just want it to run regardless of the condition we can say while true do and this will make a repeating loop which just repeats over and over again and it won't ever be stopped until the server is shut down so this will just keep on making the trucks leave and then they'll come back and then they'll leave come back teleporting people to and from the story game forever and ever whilst people are still in the game so what we're doing first is we are creating a for loop and a for loop is used to count down or count up but in this case we're counting down from 15 seconds down to zero and we're going from so look we're going from 15 down to zero and we're counting down by minus one each time that's all that we're doing here and then the value from 15 down to zero gets stored in this variable called i so we can refer to the number of seconds to left by saying i and then what we're doing is we're getting the sign and the wooden sign which is here getting that wooden sign and we're saying by saying script dot parent which is the truck and we're saying dot parent which is lane two we're getting the sign which is inside of it and inside of the sign there is a part called top which is the top part that's got a surface gui inside of it and inside a surface gui which basically projects a gui onto a surface like this there's a text label and that text label has some text so we could write whatever we want on this sign such as subscribe to alvin blocks if you haven't done that already i do recommend it so you can write whatever you want on this sign but we can also update it via a script so every second we're going to update it to say leaving in 10 leaving in 9 leaving an 8 etc so if we go back to our script here in the top you can see that we're just changing the text property to a string and a string is just uh some some information so it's a data type which holds text so if we want to write text we have to write it in a string like that but we also want to include the number of seconds left so what we can do is we can say dot dot outside of our string we close them off with a with speech marks like that or a quote mark we say dot dot i dot dot and then we have another string with a space so that the words are separated from our number and we put seconds like that okay and then we just have a weight one so that it delays from moving on to the next number if we didn't have a weight one it would count down immediately like that it would just go 15 to zero nothing in between because it's going so fast that we can't notice the difference so we have that weight one delay so we can notice the difference as it counts down each second so then once it's counted down to zero if it's out of this for loop because in a for loop it will go okay 15 we'll do the code do the code it gets to the end it will go back to the top 14. do the code to the code back to the top 13 code code you get the idea so once it gets to the bottom to this weight one once that's finished it goes back to the top again and only when it's at zero so when it goes one okay do the code zero okay we're at zero so we're going to stop and then it moves on so it will only move on when the countdown is at zero so at this point and this is a comment by the way if you see two hyphens like this it's just a comment so it's where we can add a note to self or just explain what's going on and the script will ignore it so when it gets to this point in the code the countdown is finished so we want to um get all of the players that are in the truck and we want to um move the truck and put them into the server so what we're doing is we're creating a table to store all of the players that are sitting down and then we're going to our seats um model which is here and we're looping through all of those seats again that are there in that model and for every single seat we're checking to see if that occupant value that occu can't talk occupant value occupant property even we're checking if the occupant property of the seat is it's got something stored in it okay so if there is somebody sitting in this seat we're going to insert them to this table so into the players table we are inserting their player but since it's their character that sat in the seat and not their player which is stored in the player service they're two different things we're getting their player from their character okay if we play the game very quickly you'll see that in the workspace we have the player's character in the players service we actually have their player and the player is where we want to store their player we don't want to store their character so we're calling another function of game dot players called get player from character and we are passing through some information for the occupant um and it's going to be there there the occupant i believe is their humanoid and um the parent will be the character object yes because look the occupant value is the humanoid the inside of the character so like i said earlier the humanoid is that object which all players characters have inside of and when we use the sit function to sit them in the seats we are referring to their humanoid so that will just get all of the players sitting in the truck and it will put them in this table so we now know all of the players who we need to teleport to the server so we can then do a check and if statement to make sure there are actually some players sitting in the truck because there could be no players in the truck and we would loop through all of the seats and find out that there's no occupants so this table could be empty and it would have it would have no data inside of it no elements inside of it so to check how many objects are in a table in this case how many players are in the table we put a hashtag before the table name so hashtag players will return the number of objects in this table and if it's greater than zero so if there's if there is at least one player in this table we will move the truck okay we will move the truck and to do that we're again counting up from zero to 150 we're going up by one each time though okay and this is going to be the number of studs which the truck moves by so i'm going to make the truck move 150 studs in the forward direction so it's going to go from here it's going to go all the way let's use the other truck here it's going to go all the way into them okay and that's about 150 studs away i measured it so we want the truck to move one stud at a time uh to 150 studs away and so what this for loop is going to do is we're going to count it from zero to 150 and i is our variable again the i variable will be that running counter so it will be one the first time then it will be two then it will be three then it will be four stoods and it will be five studs six studs all the way up to 150 studs so every single time this loops through it's going to move the truck forwards okay going to move the truck forwards by about one stood okay that's what a look vector is when we say script dot parent dot hit hit box dot c frame dot look vector that is getting the truck and then it's getting the hitbox part which surrounds it so basically it's just one big part that covers the entire truck and then it's getting its c frame which is its position with rotation so it's getting that and then the look vector gives us the direction that it's currently traveling in so the look vector would be facing in this direction okay and it would just it would be about one stood long so every single time this for loop loops through it's translating the truck so it's essentially moving it in a direction by about one stud each time but when you do that 150 times then it's moving it one stood 150 times and eventually you will get to this dark area and it will look like the truck is moving so essentially it's just moving forward stood order stood forward and we'll keep on doing that until you can see it's starting to you know move away from the truck the truck would be moving with it um but it would move the entire truck to the uh into the darkness here so let's just put that back where it belongs in there there we go so yeah it would move the truck forwards okay and when we move that hitbox because the hitbox is the primary part um when that primary part moves when the hitbox moves the rest of the truck will move with it so if you changed 150 to 30 for example it would only go 30 studs forward so the 150 is just how far it's going to go in studs and then once it's got to the darkness we are going to reserve a server for our story game but we haven't made the story game yet so what we need to do is we need to make another place for our story game and you can see that there's an id in the reserve server function here we're going to remove this because this will not work for us we need to create our own place okay that was from my own story game but we need to make our own so what we're going to do is we're going to go to the base plate here and we're going to click on file and then we're going to click on publish to row blocks as uh yeah we're going to produce a relax and then we're going to click on create new game and i'm going to call my game alvin blocks's story game okay i'm going to click on create and once that's created we've now created our games universe so we've published it to roblox and we can create sub places so like i said in the other video we can have one main place and then we can have places attached to it that we can teleport players to so a different place where you can have another server so we're going to click on the view tab i'm going to click on asset manager then we're going to click on places and you can see there's no places here so i'm going to right click and i'm going to click on add new place okay and it's created alvin block's place number 1017 so i'm going to right click on this i'm going to rename it i'm going to call it story place okay and now we have two different places we have the story game which is this one here this is the lobby area so i'm going to right click and rename this to lobby actually okay but this but this this is what will appear on the roblox game page right so if you wanted your game to have its own name such as like camping then you'd call it camping for example but the story place that doesn't matter because no one's really going to see that because that this is just the place where they're going to get teleported to where the actual game is going to be anyway once you've done that i'm going to right click on my story place and i'm going to copy the id to the clipboard then i'm going to go back to my script and i'm going to paste that id in here okay and this is telling the game telling the script which game which place we want to teleport the users to okay so once we've done that uh we are we are basically calling the teleport service up here at the top and this is the service we need to use in order to be able to teleport players in roblox to a different game so we say teleport service reserve server and then we give the id okay so that's like the access code to get in so we've basically said look hey roblox i want to teleport all of these players to my story place can you give me an access code so that i can let them in and then it will return the access code in the server data here and then all we need to do is say teleport service colon teleport a private server so it's going to create it's created this this is going to create this new server for our players with the place id so we're telling the game which place we want to take them to we've got the access code from the server data which we've just which we've just accessed by saying reserve server so we've reserved a server for our players to go to a nice private server for them to all be together we've got the access code for it and then we're passing that to our teleport as a private server function and we're also giving the list of players who we want to take with us okay so that's why we need to get the players earlier because we needed to have a list of all the players that are going to come with us because not all players that are in the lobby are going to be going to the story place because some might have just joined some might be in a different truck some might just be hanging out in the lobby etc and once we've teleported them we can return the trucks back to where they belong at this at the top of the lobby here so we want to bring them back so to do that we can count down we can count down again well we're counting up really from zero to 150 but we're just translating it by a negative value this time so when we translate it by a negative number such as negative 150 it's going to come backwards in the same direction and again we're using a weight 0.01 just so that each time that the eye changes to a different number you can see the car moving we have that slight delay so you can see it moving between each stud otherwise it would just move from the start to the end straight away and you wouldn't notice it so let's publish our game and let's go and try it out so i'm going to go and right click so i click on file and click publish to roblox and then i'm going to go to home i'm going to click on game settings and i go to security oh sorry i'm going to go to permissions and i'm going to set it to public or friends you can set it to friends if you want i mean it depends if you want your friends to be able to play it uh or just anyone on roadblock so i'm going to click on public and then click on save and then i'm going to click on this little link icon over here and if it doesn't give you it's not working for some reason but it should give you a link to your game if you don't manage to get the link like i haven't you can go to your web browser and you can go to the create tab on roblox i'll show you now and there'll be a link to your game so here we are in the roblox website so if you click on create in the top corner in the top middle or you go to roblox.com develop and you click on my creations you should see your lobby here so i'm going to click on the start place and i'm then going to click on play okay so here we go we have joined the place again you can see only the right side is working for now that's because we haven't put the script in the other truck but i can join my truck here it's going to leave in three two one and then the truck begins to move one step at a time and we're going into the darkness and then it's going back don't worry um we do stay in the truck but not for long maybe we should have a delay in there for about 10 seconds just to make sure the players get teleported but then you can see i get teleported to my lobby place so this is where we're going to have the story game where we're going to have the scripts contr control the story etc and that's what we will be looking at in the next video so if you want to go ahead and check that video out you can do so now the thumbnail is on the screen or the link is in the description for you don't forget if you want to become a channel member you can uh you can go ahead and just click on the drawing button otherwise let's just quickly add that script back to the uh of the truck and then we'll be ready to move on so back here in studio i'm just gonna go into the lane two into the truck i'm gonna take the script right click copy i'm gonna go to lane one into the truck i'm gonna paste it in there and it will do the exact same thing on the left side there you go you can see the left side is working as well so i'll see you in the next video
Info
Channel: AlvinBlox
Views: 46,040
Rating: undefined out of 5
Keywords:
Id: hmaewyY0vHo
Channel Id: undefined
Length: 34min 45sec (2085 seconds)
Published: Fri Oct 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.