welcome back to my Roblox beginner scripting tutorial series my name is balev and this is the final episode of our beginnner scripting tutorial guide and if you've made it this far into the series then huge respects to you because I think a lot of people would have left by like the second or third episode so the fact that you've made it this far means that you're really interested in being able to make a Roblox game and you're fully committed to making that happen which I'm really proud of so basically what we're going to be doing for this episode is we're going to be taking everything we've learned up until this point and we're going to create our first game as I'm going to show you right over here this is essentially going to be taking everything we've learned and we're going to create our first game by doing so so I'm just going to show you what this game is if we hit play when we go to test and basically what we have here is an obstacle course now this obstacle course is a little unique compared to a traditional obstacle course or Obby or whatever you want to call it so first things first is we have these yellow balls over here where if we touch it then it's going to increment our leader stat that we have up here called coins and it's going to be a random number from like I think 1 to five where if we step on it then it's going to change our coins value to something between one and five and it's going to add that to our leader stat and it's also going to make it transparent as well just like this but the main thing about this obstacle course is we have a button for each stage for this obstacle course so if we step on it then the gate at the end of it is going to open and there's going to be a timer at the output showing how many seconds we have left before we make it across so once we do make it across then it's going to close the gate and if you didn't make it in time then you would have to go down and press the button again so this is stage two which is basically the exact same thing except we have a smaller time frame so as you saw right there I barely had enough time to actually get through that thing and so we basically just continue from here on out every single stage we make is basically the same idea where we press a button and then there's a certain amount of time that is going to pass before the gate closes on the other side and so and taking everything we've learned we're going to recreate this obstacle course but I highly highly encourage you to try making this game yourself first with everything you've learned before we start implementing it inside of this episode so with that being said if you've attempted to make this game by yourself then we can go ahead and go straight into implementing so I've loaded up a fresh base plate here and it's completely up to you whether you want to create a new place by going to file and then hitting new for this episode or you could just use the same game that you've been using throughout this entire tutorial guide completely up to you and one more thing I would like to mention is if there's at any point throughout the video where I'm speaking too fast or if there's some parts of the video that just confuses you then I encourage you to rewatch those bits and you can even play the video in 0. 75 times speed to make the video slower so that you can take in the information better but once again that's up to you and now that I've addressed that let's go ahead and create our first game on Roblox so what we're going to do is go to the Explorer hit the plus sign next to workspace and we're going to insert a model now with this model we're going to rename this model to our main game just like this and then we're going to add folders to this main game and there's four of them that we're going to need so let's hit the plus sign insert a folder just like this and we're going to rename this folder to coins so we're going to need one for coins and what I'm going to do is right click and duplicate this because we're also going to need one for the gates and we're going to duplicate this again we're going to need one for our buttons and then finally we're going to need one more for the stages themselves so now that we have our folders the next thing we're going to do is create all the parts that we need to make up one stage and those three being the gate the button and the obstacle course itself so let's go and go into the home and we're going to insert a part so this part is going to resemble the button that we're going to be using for the first obstacle so what I'm going to do is rename this part to let's say stage one and I'm going to go down and I'm going to hit anchored so that it's not affected by gravity whenever we step on it and then we're also going to change the brick color of this to like really red and we can change the material of this to Neon as well and I'm also going to scale this down by clicking on the scale tool and we're going to just scale this down like so so now we have our stage one button that we have over here and we can place this inside of our buttons folder just like so okay so that's the first part but next thing we need is our gate so we're going to add another part like this and we're going to call this one stage one as well we're going to make this gate let's say some sort of green color like this and we're also going to go down and check anchored once again and we can just basically scale this up just like this so that it resembles a gate and now we can drag this into our gates folder just like so so now we have the button and to the gate for stage one but now let's create the actual obstacle for stage one so what I'm going to do when once again is insert a part just like this we can scale this however we want just like so it doesn't really matter too much and now that we have this we're going to go down and we're going to hit anchored once again and what I'm going to do for each stage is I'm actually going to insert a model so inside of the stages folder we're going to hit the plus sign and we're going to insert a model and I'm going to call this stage one again and I'm going to drag this part inside of stage one and now that we have this I'm going to duplicate this part and I'm going to move it along this way just like so just so that we have some platforms over here I'm going to duplicate the same thing just by going like this I can even take these three parts and just duplicate it like so and so we now have more to work with like this and now that we have this we have our first obstacle pretty much so what we're going to do is basically take this part and we're going to duplicate it like this and I'm also going to scale it just like so so that we have a PL platform over here and I'm just going to recolor this bit to some sort of blue and now that we have this we could basically take our gate so if we select the gate on the explore and we select the move tool then we can basically just move it up here like this if we're able to just move it over here and we cover it up so that we can't bypass it like this then that should basically be everything that we need and we're also going to take our button and we're just going to move it over here so that it's at a reasonable spot and now we basically have our setup for the first stage so now that we have this we're going to create a script and make the game functional so what I'm going to do is actually go on server script service and I'm going to hit the plus sign and we're going to insert one in server script surface we're not going to do it inside of workspace but we're going to do it inside of here instead so I'm just going to delete the script that's over inside of here and we're going to create a couple variables so the first thing is accessing the main game so we're going to say local main game equal game. workpace and we're going to use wait for child as well so we're going to hit colon wait for Child open close parentheses and then inside of here we're going to say main game just like this and then we're going to create more references specifically for the gates and the buttons so what I'm going to do is say local Gates equals main game colon wait for Child open to close parenthesis and then in here we're going to put Gates and then we're going to have one for the buttons as well so we're going to say local buttons equals main game colon weight for Child open and close parentheses and we're going to put down buttons just like so okay now we have our gates and we have our buttons but the thing we want to do with the script is we want to make this functional when we step on the button so that it can find the right gate that it's looking for so that it can open up the gate so to speak so what we need to do is basically access all the buttons and then make them quote unquote pressable or touchable by the player um one thing I forgot to do is go to our script and we're actually going to rename this to our main script just like this um just for organization purposes that's what we're going to do so here's basically how we get a table full of all the buttons so that we can go through each of them so we can make them functional what we're going to do is say for index comma button in pairs open close parentheses buttons colon get children open and close parentheses do and and then we're going to hit enter so basically we're going to use get children to get a table of all of the buttons that are inside of this buttons folder and then we're going to use this button variable to make a touched event for each and every single one of them now for this index variable we can actually just put an underscore because we're actually not going to use this key variable right here so what we're going to do now is say button.
touch colon connect function open close parentheses enter and we're also going to pass in the other part that we're trying to detect and what we need is to check whether a humanoid touched it or not so we're going to say local humanoid equals other part. parent colon find First Child open close parenthesis then we're going to look for a humanoid then we're going to hit enter and now what we're going to do is say if humanoid then and then we're going to hit enter just like this now there's something we need to add to the button that I forgot to mention and those are some instance variables that we're going to be using and changing inside of a script so inside of our stage one button we're going to hit the plus sign and we're going to insert two values the first one is going to be a Boolean which is going to check whether this current button has been touched so we're just going to rename this to touch just like this and we're going to insert another value that's an INT value just like this and we're going to rename this to duration which is going to be how long this gate is going to be open for so we can say that this gate can be open for about 10 seconds we're just going to change it to that and we can leave the touch variable unchanged and so what we're going to do is basically locate our touched variable that we have here so we're going to say local touched equals button colon find First Child open close parentheses touched just like this so now what we're going to do is say if humanoid and touched and touched. value is equal to false now the reason we're saying touched here is because we're trying to see if touched actually exists as a value and then we're going to check if the value of touched so this thing down here if it's set equal to false so it hasn't been touched yet so if we're able to confirm all these things then we can make the button pressable so what we're going to do is we can actually create a new function and just put that inside of here so what I'm going to do is declare a new function up here by saying local function activate button just like this and then we're going to put an open close parenthesis and we're going to hit enter so now we can pass in our activate button function down here and there's actually a few things that we're going to pass in so the first thing is going to be the button and then the second thing is going to be the touched variable as well so we're going to put in touch just like this so then we're going to do the same thing up here by passing in Button as a parameter and then we're going to pass in the touched um instance value as well so now what we're going to do inside of this function is say touched.
Val is equal to true and then we're going to locate the duration value as well so what we're going to do is say local duration equals button colon find First Child open and close parenthesis duration just like this and then we are now going to put a task. weight for however long the duration value is so we're going to say duration. Val just like this and then we are going to say touch.
value is set back equal to false just like so so we now have a button that activates but now what we need to do is actually make the gate associated with this stage to be I guess open so here's how we're going to do it what we're going to do is basically locate the gate that we're looking for and then we're going to open it up and the way we're going to do that is we're going to say local gate equals gate colon find First Child open close parenthesis and what we're going to oh sorry Gates that's what I meant to say and then inside of here what we're going to do is say button. name and the reason we're doing button. name is because when we're looking for the stage one button this is the name of the button and if we go inside of the gates folder we're trying to look for the same exact name so that we know that this is the state gate that we're trying to look for that's why we passed in button.
name instead of looking for the specific name that we're looking for so then once we find the gate we're going to say if gate then we're going to set the transparency of the gate so gate. transparency is set equal to 0. 5 and then we're also going to make the gate can Collide uh set equal to false so basically what can Collide is if we select gate there's a property here called can Collide and when this is set equal to true that means whenever our player is touching the part then we can't pass through it but if we set it equal to false then that means the player can actually pass through the part so that's what we're going to be doing here by saying gate.
can Collide is set equal to false just like this and so this is how we basically open up the gate for the player to be able to walk through it now after a certain period of time we're going to have to basically take these variables and make the gate back to what it used to be so we're going to select these two lines we're going to copy it and then we're going to paste it down here so I'm going to make the transparency zero and I'm going to set the can collide of this property back to true so that we now have a functioning script over here now if we want to be able to print this out inside of the output what we can do instead of a task. we is write a for Loop now what we can do here is basically say local timer equals duration. Val just like this and what we can do is write a while loop by saying while timer is greater than zero we can say do timer equals timer minus one and then up here we can say task.
wa for about 1 second and then we can even write a print statement at the very start here by basically telling us what the timer value currently is so we print the timer wait 1 second and then we decrement the timer variable by one until it reaches one or something that's not zero so this is basically our entire main script right here so if we go into the game and hit test and hit play then we should basically see our first stage be functional so if I press the button then it's going to show down here that we have 10 seconds so that we can reach this stage and we are now reaching the other side of this gate and then once the timer has finished then it's basically going to close up again so you have to go back and press the same button again so if we go back and press the button one more time then it should be working just as expected so now what I'm going to do is hit stop and the next thing we're going to add is coins so basically we're just going to go inside of model we're going to instead of creating a part we're going to hit the drop down here and we're going to create a sphere so what we're going to do with the sphere is we're going to rename this to coin we're going to set the brick color to some sort of yellow and we're going to make the material to Neon and we're also going to set anchored equal to true and we're also going to set can Collide equal to false just like this so that the player can walk through it and so now that we have this we can basically just move this inside of our platform I'm just going to put it somewhere here I'm I'm going to put it right here so now that we have this what we need to do is create a new script for our leader stats so in of server script service we're going to hit the plus sign we're going to insert a new script and we're going to rename this one to player stats just like this and now what we're going to do is create a player added event so we're going to say game. players. player added colon connect function open and close parentheses we're going to pass in the player argument and then we're going to hit enter just like this so we're going to create a new leader stat for this player so we're going to say local leader stats equals instance.
new open close parenthesis folder and then we're going to set the name of this folder so we're going to say leader stats. name equals in all lower case we're going to say leader stats like so and then we are going to set the parent of this leader stats folder to the player itself and now we're going to add a coins leader stat to this leader stats folder so we're going to say local coins equals instance. new and then inside of here we're we're going to add an INT value and then for the coins name we're going to say coins.
name is equal Al to coins just like this and then we're going to say coins. value is set equal to zero and then finally we're going to put the parent of this coin's value to the leader stats just like this so now we've created our leader stats script right here what we need to do now is basically take all the coins that are inside of this coins folder so what I'm actually going to do is take this coin and move it inside the coins folder so what I'm going to do is basically locate the coins that we're going to need for this script so what I'm going to do is say local main game equals game. workpace colon wait for Child open close parenthesis main game and then we're going to locate the coins folder by saying local coins equals main game colon wait for child and then we're going to say coins just like this now we're going to use another pairs Loop for every single coin that we touch so we're going to say 4core comma coin in pairs in parentheses we're going to say coins Co get children because we're trying to get a table of all the coins rather than the folder itself so then we're going to say do just like this and then we're going to add a touched event to the coin so we're going to say coin.
touched colon connect function open close parenthesis enter just like this and then we're also going to insert the other part as well now one other thing we're going to add to this coins variable is by adding another Boolean value inside of our coin and then we're going to rename this to touch just like so so what we're going to do first is locate the the humanoid once again so we're going to say local humanoid equals other part. parent colon find First Child open close parenthesis and then we're going to add a humanoid just like this next thing we're going to do is we have to locate the player of this humanoid because we need to be able to change the coins value of the player based on the humanoid that we provided and there's actually a function inside of players that allows us to do this so I want you to copy exactly what I do so what we're going to do is say local player equal game. players colon and this function is going to be called get player from character just like this and then inside of these parentheses what we're going to do is say other part.
parent because we are passing in the character and we're trying to see if there's a player object that exists within the character if that makes sense so then what we're going to do is locate the touched variable by saying local touched equals coin colon find first child open close parenthesis touch just like so and now we're going to do our if statement so we're going to say if humanoid and player and touched and touched. Val is equal to false then so we need to make all four of these checks and if every single check here is valid then what we're going to do first is say touch. value is set equal to true and then what we're going to do is say player.
leer stats. coins . value is equal to the same thing here so if we just copy this and paste it on the right side plus one so basically what we're doing here is we take the player we get the leader stats folder of the player then we get the coins stat then we update the value of it to whatever it currently is and then we set it equal to one now if we want to make this more readable what we can do is basically just delete this and then say plus equals 1 so it takes whatever the value of this is and it adds one to it just by using the simple compound Operator just like so so once we add the value to this what we can do is we can visually change the coin Itself by saying coin.
transparency let's say we set this equal to 0. 75 and now we basically have a finished game if we go into the game and hit play then what we should see is if we step on the button then it's still going to be visible and if we hit on this coin then it says that it adds one to our coins but there's one final touch that we need to add to this and that is adding a random coins amount when we step on the button so what we can actually do down here is say local random amount equals math.