Advanced Roblox Scripting Tutorial #17 - Region3 (Beginner to Pro 2019)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
already guys it's deaf can gear back with a brand tutorial now I'm um in today's video I'm gonna be teaching you about region 3 now you may have heard originally before it's it's kind of useful okay you can use it like when ripping terrain and stuff like that or like it's you can make it like a your own like dot touched event with it I I'm trying to think of a practical way to use it but I can't but listen it's very useful and you will probably use it one day so in today's video I'm gonna be teaching you all about it okay so um first things first for you in the video if you are new to scripting in general you guys should definitely go check out my beginner series because you might find everything here confusing but other than that let's go ahead and start all right I'm gonna leave my script I have right here and I'm gonna go ahead and insert a new script into the oh crap not on model scripts sorry a new script into the server script service also guys you know use code tap you know what I'm saying okay I have a code yeah okay anyways let's go ahead and start okay so first things first what is a region 3 okay um so the best way to put this okay a region 3 or we're gonna intrical it a reason you know whatever you want is just like a region okay so this part right here okay it's it's pretty big okay the size of it you can find right here okay and basically everything in this part or this entire part like this area would be considered a region if I made it one right but right now obviously it's just the size of the part so let me actually make a little transparent so you can kind of see it so this is a whole region okay and I can go inside of it and I can do whatever I want and basically you can make these with scripts right and you can make a region or from a part or you can make a part from a region you can do ever you want so what we're gonna do is I'm going to actually make a region and and then make a part to show the region okay so first things first we're gonna go ahead and type local region okay and then we're gonna do region 3 dot new and okay guys this is looking fusing so far I'm sorry trying to think of a good way to explain region threes I feel like I'm doing a bad job but listen I'll explain it eventually okay so don't worry okay anyways it's just just follow along I guess okay so we're gonna do Region three dot new and then we're gonna do vector three because we have to get like okay okay so how you make a Region three is you need two values okay you need to see the vector three minimum and then the vector three max and basically what that means is we need like the bottom left point of a part or like I'm an area right so like we need this point right here and then we need this point it's hop right point and then it's gonna actually calculate this entire little like box right here and it'll make it all a region so yeah so what we're gonna do is we're gonna do Region three new and then we should make a we have to make a point the bottom bottom left point so we'll do vector three new and then we'll do zero zero or actually it will do like five zero five okay and then we'll do another comma and we need to put the maximum point so we'll do vector three new and we'll do 15 15 15 okay and now if I were to run this obviously it's not displaying anywhere it's just in the memory but it could display someone somewhere if I wanted it to so so what we're gonna do actually is I'm gonna show you guys what the region looks like by making a part out of it okay so I'm gonna go ahead and don't do that sorry okay put their other parenthesis there okay so we're gonna go ahead and get a new parts we're gonna do local part is equal to instance dot new then we're gonna name part obviously okay and then we're gonna do part dot size is equal to region dot size okay so we just made the parts is equal to the region to us size and then we also need to anchor it's actually gonna anchor it before that so doesn't follow the map so let's get part not anchored equal true okay and and then when you actually give it a parent so where do you want to go obviously we want to go to the workspace so part dot parent is equal to game dot workspace and then we'll make it not collide so part I can collide equal to false let's go ahead and hit play and see what happens and I'll delete that so it's gonna create a part out of this region right here so let's see if this works and if it doesn't I'm gonna cry but it would so there it is okay we just fell through it but as you can see here it made up part okay um you do see like that okay so like the bottom left corner is actually equal to five zero five so I'm not sure which one it is but it's one of these corners right and the top right is equal to 15 15 15 so it's it calculates it like from the bottom left to the top right and it makes this huge box now if I were to delete this whole part right here you wouldn't see that box obviously because I didn't actually make anything with the region but that's what it does okay so yeah that's kind of cool and yeah that's pretty much it okay so now we're going to actually make the region we can make the region do stuff okay so we're gonna make it like be a little dot touched event I'm pretty sure that's how the roblox like built-in dot touch event works with region threes I'm not sure honestly but I would I would assume so but anyways we're gonna do while true do okay and we're gonna do wait we need to put a weight function in there okay and then we're gonna do local parts all right no no yeah yeah oh yeah so we're gonna have to define the parts in the region okay and then we're gonna loop through them and then we're gonna see if it's a player and if it's a player we're gonna like kill the player something like that okay so we're gonna do while Trudeau and then wait and then we're gonna do local parts in region or getting whatever you want and then we're gonna do is equal to work space and then : find parts in region 3 okay now before we go on here if you can see right here it says find parts and region 3 and then it says 5 parts of region 3 with a ignore list and then it centers finds part of five parts that region through with whitelist now basically what this means is if you want to find parts in the region 3 right you can have a whitelist to only find those certain parts and only set a table equal to those parts or if you want to ignore some parts you have a table right and you can as you can see are the parameters for it you can put a table of parts you want to ignore I vote for this census we're just going to do fine parts in region 3 so we can redefine every part and then it actually allows you to ignore one part if you want to so let's go ahead and type fine parts in region 3 I'll hit enter and it takes three parameters first things first obviously the region that makes sense right so we're gonna do region and then we're gonna do for the part we okay so the next parameter is the part to ignore if you want a part to ignore personally I don't want any parts to ignore so we're gonna name it nil and actually wait a minute we do we want to ignore this part okay cuz we don't want it to just keep putting like okay so like EC and makes this part right here we don't want it to actually put that part in there cuz you already know it's at that's the region so we'll just put part in there because we named this part and then we're gonna go ahead and do the last parameter which is C like when you forget stuff sometimes you know you got to go back what is the last parameter in a minute the freshman workspace find parts in region 3 less parameter is number of max parts so what's the maximum you want to make this you know that's that's what it is so we'll just do like we could be like math a huge to make an infinite but we're not gonna do that we'll just feel like 100 something okay we'd only need that many parts i she'll do a thousand okay anyways next we're gonna go ahead and loop through this table okay and then we're going to see if there's a player that is in the region okay so we're gonna do 4i part in pairs parts in region okay and then we're gonna do if part dot parents so it's gonna see like if okay so basically it's gonna loop through this loop every like millisecond right and then it's gonna make a table and it's gonna look for every part that's in this region right here okay and we've made the region crap it's not gonna show because I'm currently a little writing something but it's gonna loop through this table or hey it's gonna everything like you know like a second is gonna loop through this loop and it's gonna make a table of everything that's inside this region right here okay everything is inside there and it's gonna put it in that table and what we're doing is we're a loop through it and then we're gonna check to see if the players in there okay so yeah all right so now we're gonna do if a part dot parent is equal or if part our parent find first child humanoid because only the players have humanoids or a little character to do I mean if part dot parent find first child is humanoid then we're gonna do prints player found in the region okay and then we'll put it like a little coal in there and then we'll put a space so we can concatenate it and then we'll actually print the players or the players name so we can do part dot parent dot name and now that'll print the character's name sorry okay there you go and then um that's pretty much it and now what we can do is we can kill it if we want to so the we'll do local char is equal to part dot parent right that should be that should be it right and actually I'll print that because I'm not a number sensor so but there you go it's let's go and test it out and see if it works and here we go and oh wait wait wait wait wait what the heck it didn't for anything your slightest you guys don't worry for eye part if part not parent fine first child humanoid okay let me move that let me move this down a little bit to make it like on ground level uh put on the other zero and then also I'm gonna make the transparency that part a little bit so it's better point nine and then um if part up here five first challenge humanoid not equal to nail maybe that's it let's test that out and see if this prints okay yeah okay make that say if part dot parent find first child humanoid is not equal to nil if you guys don't know this little sign right here means not equal to so if I'm trying to African I think my way to explain that so but I hope is make sense like if the part right so basically if my body part that's it and then the parent of it and then which would be my character right and then you find the first child humanoid which I have and then if that's not equal to nil than we know it's a character so that's it also that's sure I think what that okay so they'll make sure that let me print the charred or a parent or parts dot parent knee and make sure it's the player because that should remember the characters right that should be I just want to make sure so you guys you guys printing is useful okay it's not useless okay so it is there we go and then we're gonna go ahead and do something with the players or the character so what we can do is we can just kill the player or kill the character I keep saying the wrong things will you chart out humanoid and then we can do : take damage if you guys ever need seen this function before person so much mandatory its use it on the humanoid and it just takes away damage from the are takes damage to it or you can do chart out humanoid is equal to about health is equal to charge a monoid dot health minus 100 right but we'll just do charge humanoid take damage and then we'll actually just make it take the max health okay so the max health limit of a normal human always 100 so we'll just make it take a hundred health from the character and make it die okay so let's go and test it out and see if it works and okay come on it should and oh okay geez my entire body has exploded also don't don't mind my character okay um I know I may look a little weird but listen I can explain okay just don't worry and um anyways so yeah that's how it works awesome hope that make sense to you guys that's pretty cool and if you guys were wondering why I didn't print again actually there's actually I have more explain so don't leave yet but if you see like it kills me once right and then it doesn't happen again and and that's because I need Alexi look through it another time but that's fine you guys understand that oh okay did kill me again alright um very cool so now we have a spawn killer it was like okay no I did this okay okay so it's broken first time alright but yeah so as you can see there that's like a dot touched event and also if you gotta see that it prints a bunch of times like it says times 233 and it that's because like every body part that touches it runs or it's we're gonna be running every like millisecond array because the weight is empty so it it gets all the body parts and every time the body part touches its printing okay hope that makes sense it's the same thing with a dot touched event like a no print a bunch so yeah alright anyways next we're going to go ahead and I'm actually going to show you how to make a region from a part okay so it's a lot cooler kind of so okay what we're gonna do is actually put a multi-line comment right here so we're gonna comment this out real quick if you guys don't know that's the multi-line comment so we're gonna go ahead and comment that out and that way that doesn't make a part now so yeah and also as you can see here there was a part we wanted to ignore which is this part so we're gonna make that equal to nil and yeah also I push it a name that part when that was part but it's okay I mean it still works so yeah I make that equal to no because there's no part to ignore now okay so what we're gonna do is we're gonna go ahead and grab sorry we're gonna go ahead and grab a part right here okay and then we're going to make it as big as we want to make it so if you want to make it big make it big make it small do whatever you want okay all right here we go and I'll make it like this and I'll make it like that then I'll make it transparent a little bit so it looks cooler and then I'll make it mmm blue or alder yeah alder okay now you have it and the shadows calculate oh gosh it looks so weird like see the shadows like just like yeah it looks so bad anyways that's that's not anything to do with our phones just maybe that computer or something I don't know but okay so now what we're gonna do is we're gonna actually make the region from the part so we're gonna do local okay okay we're gonna name this to region part okay region part oh wait I want to make sure the Capitals look nice okay camelcase you understand alright so we're gonna do local region part is equal to game dial workspace region apart okay and then we're going to actually define the positions that we need to use for the region okay so as you as I told you earlier it takes the bottom left part right or the bottom left point of the part of the vertice and then it takes the top right and then it calculates all the other points and makes it like like like a rectangle or square right that's what it does that's how regions will work okay so what we're gonna do is we have to find the bottom left point and the top right point but how do we find the bottom right point and it's a plant well you have to use some math okay now this might get a little bit confusing it's not very confusing it's pretty simple to understand I'll try to explain as best as I can but um you have to use math okay so what we're gonna do is we're gonna go ahead and do local position 1 is equal to region part okay dot position and then we're gonna do - okay region this new look so gonna be using isn't it - region part dot size / - okay all right now if that doesn't make sense don't worry it will okay I promise and then I put this in parenthesis because I want to make sure that this all looks good right and it does this first even though according to PEMDAS it will but I put his emergencies because I want to make sure it divides that first okay so what it's gonna do is it's gonna it's gonna do okay the region part dot position okay it's gonna find the position all right which is this all right I'll make it a better number maybe I'll make it like five zero fifteen okay and we need to make it like five there you go all right so it finds a position okay and then it a - is it or it's a and then it subtracts the size of the region okay so whenever you get to position right it's really getting the center of the mesh or the center of the part okay so that's what it's giving you all right so that's what you're doing you're getting the size okay I'll make these whole numbers with a little bit easier to look at there you go let me actually put my modelling to one stud there you go and that's oh no okay whatever it's fine all right so you be here the point okay so eight this is I'm sorry it's hard to explain okay so it gets the position and then it subtracts the size of it - - okay so it it does like the size okay and then I divide I mean / - okay and then and then - the position so hope that make oh then you know what I'm gonna stop talking I'm going to do the next one okay so then local position 2 is equal to region part dots position plus region part dot size / - okay so we're doing the same thing with only differences there's a plus right here so it goes to the top right instead now I know I'm gonna visualize this but it'd probably take a little while to write it out but I'm just gonna say it what it does is this funk or this math function right here all it does is it finds the bottom left point and then this one position - finds a top right point okay it's pretty pretty simple to understand maybe you're a little hard to visualize but that's what it does okay there you go alright so then we're gonna do local region we're gonna make the region and we're gonna say local region is equal to region 3 dot new position 1 position - ok now also you don't need to have this part like ok whenever he made this that first region remember we made that first region and we made a part with it we didn't even we didn't need to have that part there we could have had the region right and it could have just been a nice little region and it would've looked nice but we made a part just to visualize it but the region could have just been invisible no part it will only be known through a script right and it would still work in this and it would still kill you all right I hope that makes sense so I'll show you what that looks like in a second here but um let me comment this out again are there we go alright so now it's going to create the region and it should work now I listen to rename this as you can see here it says local oh no that's actually good because I mean the region right there alright so that should be working all right so let's go and test it out and see if this bad boy works all right here we go now also I'm can collide might be off and anchored might yep oh no all right so okay so let me first off let me turn critical I it off there we go and let me anchor it - all right I'm gonna go ahead and play and I'm it's gonna actually default spawn me on it because that's worth it ok let me move it let me yeah all right by default it's gonna spawn me on it because obviously like your character spawns on the origin and that's where the part was I filled up that so now if we walk over to the region okay which is made out of this part this entire part is region because we made it from the part we're gonna walk into it we're gonna die ok because we still have this function right here which kills you ok pretty simple stuff um so yeah that's pretty cool and also what we can do is let's say we make the playlist let's say we wanted a region that was like this big okay you wanted this entire region right here and I'll move it over a little bit and then what we did is we made the region but then we're like you know what we don't want this part though we don't want people to know that's a region here so what you can just do is just delete the part right you can just do a region part destroy there we go and then you hit f5 and if the region is going to be there but the part wool so look I spawn in and I think the readers over here let me walk over and see I still died because the region is still there in the memory it's just you don't see it it's not visualized ok so that's the same thing when we make this part over here it was still a region you can still use it but we made a part just to show you better I made a part of show you better but if I delete that part it would still kill you so yeah as you can see here it still does so yeah this can be pretty useful like maybe he wanted to play music in a certain area or if you wanted to have like a cell area of your game or you know whatever you want it but anyways guys I mean I managed the story before it gets way too long but that is pretty much it I hope you guys enjoy the tutorial if you did and if this made sense I hope it did leave a like and have any questions or comments between the discord server link in the description below and also leave a comment if you that'sthat's what you want to do so yeah that's pretty much it guys I hope you enjoyed and I will see you in the next one use code tap ok alright subscribe like alright
Info
Channel: TheDevKing
Views: 47,348
Rating: undefined out of 5
Keywords: TheDevKing, Roblox Scripting Tutorial, roblox, studio, coding, tutorial, roblox studio, advanced roblox scripting tutorial, how to script on roblox, region3 roblox, roblox region3, roblox studio region3, what is region3, how to make a sell area in roblox studio, roblox studio tutorial, how to use region3 roblox
Id: kRuSWSe9faY
Channel Id: undefined
Length: 22min 4sec (1324 seconds)
Published: Mon Dec 02 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.