Advanced Roblox Scripting Tutorial #4 - Common Built-In Functions (Beginner to Pro 2019)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all righty guys is it f king here back with another video and welcome back to the advanced series guys welcome back to your fourth episode I think it is now and in today's tutorial we're gonna be learning about a few common built-in functions that you're gonna need to know for the future now the reason why I'm kind of teaching about these now which I probably could have mentioned in the beginner series but I kind of just forgot about these and these are just important things you're gonna need to know because other pretty common ones that you're gonna use so um yeah but anyway scribe before we're gonna the video be sure to leave a like okay cuz it helps I think and also if you're new to the channel be sure to watch the videos before this and the beginner series rolls you might get very confused so yeah anyways let's go ahead and start alright guys so first things first let's go ahead and make a script in the workspace so there we go we're gonna insert a script there and I'm really showing you guys a few of the common built-in functions now the functions I'm going to be showing in today's video are these ones okay now these are kind of random they don't really correlate with each other too much but basically what they do is you know just very important and they're pretty common and I need to I need you guys to know them for future tutorials so we're gonna go and start off let's get children now also guys I'm sorry from being a little bit quiet right now it's kind of late at night and my parents are sleeping cuz oh yeah anyways so anyway so what we're gonna do now is teach you about this one okay so we don't get children here now get children what does get children do okay so for example if we start our character okay or if we start the game right okay so basically it takes so long the load man this is so annoying but basically I'm gonna be teaching about get children okay so get children and what it is it gives you a table okay now let me show you what I mean so if we start the game right now okay this is me okay and I go my workspace you can see I have my character right here in the workspace right walking around in the workspace this is him right here okay now if I go into here okay if I click this little arrow I have all of the children of my character in here right now basically what children does is I could do game dot or no sorry I could do dot workspace dot half-water RB elects which my username and then get children and it would return all of the children into a variable which should I normally do so character children write equals game network based on farm I relax get children so basically it would get all of my um all of my parts in here and all of my instances I mean everything in here become a part of the table and it would make a table called character children so yeah that's what got children does it basically creates a table off of a variable so or off of like you know something often an instance I guess so yeah basically that's what it does it gets all the children pretty self-explanatory and now with that like okay like so for example right look okay actually I know really cool team what you do okay look so if we had a few parts right here okay we had we had this part we had part one i should all just name it one two and then we had three okay we got all three of these parts okay now what we could do is we can make them all into a model which is just kind of groups them together and actually I'll make a folder real quick I'm gonna put them all into a folder so I have all these parts right here put them into a folder we're gonna call it parts okay these are our parts right here right there in folder now what I could do with these parts is I could delete all of them really simply now let me show you I mean so if you guys don't remember but when I talk to you about tables what I did was I did local you know local part 1 equals game Dowler expose art 1 and then I did the same thing for this one I didn't look apart too now there's an easier way to do this which is just getting the children of the folder so what I could do is local parts is equal to game don't work space dot parts get children now basically what it what this is doing is getting all of these parts right here and it's putting them into a table called parts now what I can do is I can loop through parts so for IV in pairs parts - and then I can do V destroy so basically you should know what this means um this is a four I this is a four in pairs loop which I taught you about basically it's saying for everything in the table loop through it and then this is the value so this is what it is so for example is going to loop through the first part which is part one and it's gonna go part destroy and there's a second one there's a part destroy and then third one obviously and then it'll just destroy that one two so I'm gonna put a weight function on it so we can see it live and I'll just run it and actually just watch it from here so I could deleted it delete it it boom so yeah it deletes it like that that's pretty cool it's easy way to do that and yeah that's pretty useful function you'll be using that a lot later on and that's what it does so yeah let's go ahead and put that all the way down here now okay next thing wait for child now wait for child is very very important I'm not sure I tell you guys about this yet I don't think I did but basically wait for child what it does is um it basically it waits for the child right so you probably wondering what do you mean wait for child so for example right in roblox do you guys you guys know that the scripts whenever the game starts the scripts run like instantly right because there's no wait nothing is waiting for it the scripts will run instantly so if I wanted to if I were to do that if I were to do game dots okay wait if I were to do game dot players let me delete this real quick asking my way I want to do game dot players dot tapwater are real X which is my username I could do local player or local character is equal to game the players or no game dot workspace my pad this would eat given my character right this would give me my character and basically this will actually air this is the code is correct right if I go in the game and I go on workspace never I had tap on our relax in the workspace right so the code is correct and it should be working but it actually gonna give me an error let me show you just why so basically if you saw it there it says right here workspace script for orphism or Saturday applied for basically it gave me an error and it says tap on our RB Lex is not a valid member of the workspace but if you go in the workspace I'm right there so why does it say that in the reason why it says this is actually because I'm sorry I'm so quiet the reason why it says this is actually because um you know that the character loads it has to load in right but the script runs so fast that it actually runs before the characters even in the game so how you fix this is you do game tile workspace wait for child right oh my gosh that's annoying wait for a child and then BOOM so now it's going to do the same exact thing but it's gonna wait for the child so now it has now it didn't give him the air because it waited for the child and it got the child because I'm loaded in so basically you're gonna use this for you know pretty much because you know just to wait for stuff to load it out on the make sense but you used to it I mean I hope and basically you can put a variable inside of here too if you wanted to but the name I wanted was time when I relaxed as I put that in quotes as well so yeah that's what that does I hope that made sense so we for wait for child okay sorry okay so get service what does get service do so in roblox are a bunch of services okay for example if you go on the right side here in the explore the work space learn to the players lighting replicated for first hour replicated storage server script service server storage these are all services that's what they are that's what they're called there's services right and that you know they serve a purpose obviously and basically how you get these or how you get them into your get them into your variable or starting a variable get them into your script is you know you go ahead and make a variable so I'll just remit to I'm gonna get replicas distal rich right some of the local replicator storage is equal to game dot can't service a replicated storage these are there's a bunch more services like marketplace servers which you use for game passes there's row box replicated storage there's a bunch more services but basically these are the losses the visual ones right and but that's how you get the services so yeah now you obviously could just do came down replicas storage but this might give you an error sometimes too so it's better to do game get service replicative storage so yeah anyways that's what that does so obviously that may seem a little you that may seem a little bit useless right now because you guys don't even know her uh placated storage does but soon we'll be using it so that'll be important anyways so next so fine first child okay so fine first child what does that do okay oh sorry about that fine first child basically what it does is it finds the first child now actually let's go ahead and read about it so if you go into part here I'm going the object browser which you get by pressing view and then go to object browser right here if you click on part find a part in here the instance part pretty much every single thing every instance has for a find first child these are pretty important ones right but basically what fine first child does is its returns the first child that matches the name of the argument now that sounds a little confusing but I'm trying to think of an example okay so okay okay look here's how it works right so for example if you had a bunch of parts in your workspace right and they were all carved oh oh my gosh okay they were all called part right so they a part part and you know part okay you could if you did oh crap if you did it game down workspace dot part what what part am I getting there's three things called part now basically what fine first child does is it finds the first child of our finds this the first one right it just finds the first one called part and obviously put that in a variable too so we'll do local part equals game to our physics I'll find first child part now this would work if I were to do game that workspace dot part it would give me air because it wouldn't know what part so yeah anyways but there's also a much more useful reason to use this which is because it actually has a second parameter as you can see here which is an optional one but basically what it does is it'll actually look for the first child right called part but if there's nothing in workspace called heart it'll actually look inside of another thing so like for example you see I have this folder right the fours in the workspace but the parts aren't well the parts actually technically are but they aren't directly in the workspace that are in the part now if you ran this right now and actually wouldn't find a part because it's looking only in the workspace but if you put a comma here and type true it would look not only in the workspace but in the child's or a space of the child so yeah I would look all the way through so yeah but if you don't want that then you can leave that empty or type false so it wouldn't look there so now I wouldn't find it so yeah anyways that's what my first child does okay now we got clone right here okay so most good no clone what is clone do okay so clone pretty simple it clones apart okay you got a part it'll make it another one let's go and write some let's write some code for it your enemy so we're gonna go ahead and make a big part make it look cool there we go there we go okay now we're gonna clone this part and duplicate it basically this is how you duplicate stuff from the script so how you do this is you could do part are you okay so we're gonna get the variable called part which is in game that we're spaced apart and then what we're gonna do now though as we could just do part clone right and this would work it would clone it but the thing is when it clones it would put it in the exact same spot so you wouldn't even notice was there so you so you're probably thinking well if you want if you want to clone it you got to move it around somewhere right so basically you would to make another thing so you would you could clone it into a variable so local part 2 equals part dot or part Cologne and now I have the part 2 and I can move it so I can do local part 2 I don't know I'm sorry not local part 2 we can do part 2 dot talk to you top position is equal to vector 3 dot new and then we can do 101 ok so now we're gonna duplicate it and put it in the sky so let me actually put a weight here so we can watch it happen so yeah ok I want to see that actually basically yeah okay so here as you can see there's no part in the sky but it's waiting it's gonna duplicate the partner moving in the sky so I'm zooming out let's see did it work that did it okay that that didn't work I'm not sure why I didn't work to be honest with you I'm not really sure at all um I think I have this syntax wrong to be honest but I I don't okay listen basically what this does is it clones apart okay it's pretty simple that's what that's what it does now you can just delete it right away if you wanted to but that's it's what it does okay now I you guys actually so that's what that's what cloning does right it makes it duplicates the part but make sure you equal it to another variable so you can manipulate the part and actually wait a minute before I actually skip on let me get rid of this and you actually see a duplicate and explore here but it didn't clone I'm really confused okay I'm not sure why I didn't clone this is really weird maybe it's not planning because oh I'm so stupid okay okay guys so alright I'm glad I forgot about this okay guys this is when it comes to scripting sometimes you forget stuff okay so I'm sorry if I kind of forget stuff sometimes but that's part of scripting you gotta try you know try stuff and if it works it works good you learn something if it doesn't work well then you know we'll try again try something else so yeah I hope that that's pretty important to know where you're shrimping but anyway it's basically the reason why and actually didn't move is because the part cloned right it duplicated the part but it doesn't know where to go so I made part two but it wasn't anywhere it was actually just in the memory of the game which is basically means it's nowhere so I can do I can do part two dot parent is equal to workspace and now I would go in the workspace so actually we'll do game at which this but basically now it will actually duplicate you'll see it there solution I mean so Yuri go see now we got two parts now during in the same spot I'll actually there move over a little bit cuz I have collisions on I'll show them off okay but yeah you see here that's what they do okay it duplicates it now we have two parts so yeah okay so make sure you set your parent to after okay also we'll know where to go once you duplicate so yeah okay anyways now for the last built-in function you need to know but she actually already should know I've taught you about them I've probably used them a few quite a few times but basically you just destroy stuff okay you can do local part equal scheme the whole workspace part and now I have my part here right and anything okay I have my part here and now I just do part dot two story and basically what this function does it's pretty simple it just destroys the part so now there's no part there anymore okay it's it's gone alright so yeah that's pretty much what that does so you guys have learned quite a bit in this tutorial you've learned about destroying you've learned about fire first child learn about wait for child and you learn about get children and you learn about get serviced so yeah if these and only makes sense to you please be sure to join the discord server the link is in description and ask your questions please please do other people will help you not just me and also leave a comment if you can to the short server anyways guys that's pretty much it for this tutorial it wasn't quite a long one but it's some pretty important stuff it wasn't too complicated nope it wasn't too complicated at least I don't think it is but yeah sorry I'm so quiet - sorry I just didn't like the ASMR you gotta just deal with that for now I mean the next tutorial be fine so don't worry but uhm yeah anyways guys I sent a tutorial and I'll see you guys in the next one peace out
Info
Channel: TheDevKing
Views: 58,519
Rating: undefined out of 5
Keywords: TheDevKing, Roblox Scripting Tutorial, roblox, studio, coding, tutorial, how to script on roblox, roblox studio, buiding, scripting, robloxstudio, built in functions in lua, roblox studio scripting, how to script in roblox, advanced roblox scripting tutorial, beginners roblox scripting tutorial, how to code in roblox studio, how to script in roblox studio, how to script in roblox studio 2019, best scripting tutorial roblox studio, best roblox studio scripting tutorial
Id: w4k_WRg4da8
Channel Id: undefined
Length: 16min 57sec (1017 seconds)
Published: Fri Aug 09 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.