TextButton - Roblox GUI Tutorial #3 — Transcript
Full transcript
- 0:00hey thanks for stopping by in this episode of my Roblox GUI tutorial guide we're going to be going
- 0:05over text buttons so in my last video we went over text labels and getting to know a little
- 0:10bit more about GUI properties and in this episode we're pretty much going to be doing the same thing
- 0:14I'm going to introduce you to text buttons and then we're also going to be looking at more GUI
- 0:19properties and we'll be adding scripts to these buttons to be able to make them functional inside
- 0:24of our Roblox games so first things first what is a text button it's basically like a text label
- 0:30except you can interact with it by clicking on it that's like the easiest way I can describe it so
- 0:35you know how with text labels we were able to show them up on our screen and we were able to change
- 0:41the text that was on those text labels and modify them through script but all we were able to do was
- 0:46just look at them there was no interactive part to those text labels but now what if we had a text
- 0:51label except we can actually interact with it by pressing on it that's where text buttons come in
- 0:56so the way we're going to create a text button is the same way we created a text label we're going
- 1:00to first add in a screen GUI so on the right side I I'm going to say this again we need to have a
- 1:06screen GUI in order to actually display our GUI elements that's the only way we're going to be
- 1:11able to do it so make sure you have a screen GUI and started GUI I called it main GUI and
- 1:17let's click on the plus sign so we're going to add in a text button which is down here and as
- 1:23you can see just like with text labels it's shown on our screen uh but there are two differences to
- 1:28this button so the text says button instead of label and we're able to and we're able to hover
- 1:35over this button as well so as you can see when we hover over the button then the color of the button
- 1:41goes a little darker to represent a button so that we're able to click on it so same thing with text
- 1:47labels we can move this around on our screen we can even change the size of the button as well
- 1:51so nothing new there and most of the properties here are very identical to text labels so that's
- 1:57one good thing about this is that a lot of the properties properties are transferable
- 2:01but now what we'll do is we'll go over more GUI properties that I haven't covered yet in this
- 2:05tutorial guide so the first property that's unique to text buttons is this property here called Auto
- 2:11button color basically what this does is you know how you can select this button and it changes the
- 2:17color of the button whenever you hover over it Roblox does this by default because this is an
- 2:23easy way for us to recognize this as a button rather than a text label but if we unselect it
- 2:29then we won't be able to hover over this button to not make it seem like we can press this button
- 2:33if we turn it back on then we're able to make it look like we can press this now you can do this
- 2:39manually through scripting but that's like a lot of boilerplate code that's very redundant because
- 2:43you're going to have to do this for every single text button which is why Roblox provided a simple
- 2:48check mark on whether you want this property to be enabled or not the rest of the properties in
- 2:53this episode we'll actually dive deeper into the text category and the first thing I'll show you
- 2:59is this text right here that says text scaled so in my last episode I went over text size which
- 3:06is basically you know the size of the text that's inside of our GUI element so with this little tiny
- 3:12text that says button we can change the text size to something a lot bigger so that we can actually
- 3:17see it now there are a couple issues with this text size property um if we change the size of
- 3:24this button then it's not going to change the size of the text alongside with it so that's definitely
- 3:32an issue so what if we wanted to make it so that Roblox will automatically scale the buttons text
- 3:38size along with the size of the text button we can do that with a property called text scaled
- 3:46so if we select this you might have noticed that nothing has changed but if we scale this down we
- 3:51can see that Roblox is automatically scaling the text as we scale down this text button so this is
- 3:59one of the most useful GUI properties that I've ever worked with when making GUI elements and for
- 4:07most guis that that you create I highly recommend turning on this text scaled option but you might
- 4:12ask if we have text scaled on then what happened to text size well text size is basically useless
- 4:20if we have text scale turned on because if we try changing the text size to something different now
- 4:26that we have text scale turned on like 100 for instance you can see that the size of the text
- 4:31did not change at all but if we turn off text scaled really quickly we can see that now we see
- 4:37the effects of text size but if we turn on text scaled again it'll just go back to what Roblox
- 4:44automatically scaled it to based on the size of the button so like I mentioned most of the
- 4:49time you should have text scaled on rather than use text size because text size is very limited
- 4:55and you definitely have to be very precise when you're using text size compared to text scaled
- 5:00it just saves a bunch of headache which is why I suggest using text scaled unless for specific
- 5:06situations where you want to have a small button but then you want to have the text size be uh a
- 5:12very specific size like maybe something that's a little bit smaller than this or maybe something
- 5:16that's a little bit bigger than the text button so it's for like very precise scenarios if you if you
- 5:22choose to but most of the time I have text scale turned on rather than using the text size property
- 5:28so the next property we have is text wrapped so let's just disable text scaled really quickly so
- 5:33that I can show you how this uh example works and let's make the text size something smaller
- 5:38so that it fits the box like 54 uh so text wrapped is basically saying how do we want to handle the
- 5:47text whenever we have a size that's smaller than the text itself so if we scale this down we can
- 5:55see that Roblox is putting the text that used to be on the right side here down to the next line
- 6:02because it's not going to fit in the first line so instead of just making it go off screen it just
- 6:08simply puts it down here so that's essentially what text wrapped is but if you have text scaled
- 6:13turned on then you won't find any use with text wrapped because Roblox just automatically scales
- 6:18the button down and the same thing can be said for this next property called text truncate this
- 6:25is a very specific property that I don't use at all but if you want to know about this property
- 6:32but I think it's still pretty good to know about in case you do want to use it so text
- 6:35truncate is similar to text wrapped except this handles uh offscreen text differently than text
- 6:43wrapped instead of having the text drop the next line instead what Roblox is going to do is that
- 6:48it's just going to hide the the text that's not showing on the button but instead replacing it
- 6:53with a bunch of dots uh to show that there is more to the the text so what I mean mean is if we go on
- 7:00the right here and we click the drop down we can see that there's an option that says at end if we
- 7:05press this and we disable text WRA and we scale this down we can see that Roblox has added three
- 7:13three dots over here letting us know that there is more text to be seen if we scale this button back
- 7:19up again it's very specific I think it's still pretty good to know but in case you ever want to
- 7:25use this but I personally never use this so take it for what you will and then the last two text
- 7:30properties we'll go over in this episode is text X alignment and text y alignment so let's just scale
- 7:37this back up again really quick and let's Center this to the center of the screen so text X and
- 7:43text y alignments are basically two properties that tell us where do we want the text to be
- 7:48aligned on this text button so right now it's in the very center of the button but if we change one
- 7:54of these properties so let's say text X alignment to left then it's going to go to the left side of
- 8:00the button and if I change the text to add like more stuff to it then it's just going to start
- 8:07from the left and then it'll keep adding to the right now let's make the same thing happen but
- 8:12this time on the right side so if we make this on the right side it'll show up like this and then if
- 8:17we add a bunch of stuff then it'll still stay on the right side and the same thing can be done with
- 8:24uh text y alignments so we can let's put this back on the center and we can change our y alignment to
- 8:32bottom and top so top will make the buttons text go on the top and bottom will make the
- 8:38text go on the bottom so pretty self-explanatory stuff I think you'll find great use for this when
- 8:43you want to put the text somewhere specific in your GUI elements and so that's also something
- 8:49important to know about all right now let's get into the scripting component of this button so
- 8:53let's just quickly change text scaled back to true so that we can see the text fully without
- 8:58having to manually change change the text size so there's four events I want to introduce to you uh
- 9:03starting with the first one so first thing we'll do is we'll go on the right side inside of main
- 9:08GUI we're going to hit the plus sign and we're going to add in a local script so let's delete
- 9:15this and let's first make reference to our GUI so we're going to say local GUI equals script. parar
- 9:22and then we're going to make reference to our text button by saying local button equals guy do button
- 9:30or text button I mean and the first event I will introduce to you is mouse hover so when we look
- 9:37at our button we can see that when we hover over the button the color of the frame changes when we
- 9:43hover over it that indicates that the player's Mouse is currently being hovered over it so we
- 9:47want to catch that and do whatever we want it to do when we hover over this button and we can do
- 9:54this using a event called Mouse enter so we will do that by by saying button. mouseenter connect
- 10:04function and then we're going to drop a line down here and then we're going to say print player has
- 10:13entered in the button and so when we go into the game hit test and hit play then what should
- 10:20happen is that when our when our player Mouse hovers over this button then we should see the
- 10:26print statement down below so if we hover over this then it will print one time in the output
- 10:32saying player has entered in the button if we hover over it again then it'll print it again
- 10:38there's basically another event that complements this called Mouse leave so this is basically when
- 10:43the player enters in their Mouse but then leaves the button after they've entered in so we can do
- 10:50that by saying dropping two lines down here by saying button. mous leave colon connect function
- 10:58open parentheses close parenthesis and then we can do the same thing here by saying player
- 11:03has left the button and so this will pretty much fire whenever the player leaves the button after
- 11:10entering into the button so Mouse leave cannot be fired until Mouse enter fires first all right
- 11:17and so now there's two more events that I want to introduce to you so now let's make an event that
- 11:23happens when we actually click on the button and there's two ways of doing this so we're going to
- 11:28do that with our left Mouse button or or if you're tapping it on the iPad or if you're using right
- 11:34trigger on Xbox or even on Playstation as well so we're going to do that using an event called
- 11:42Mouse button oneclick so this is what it will look like let's drop two lines down here we're going to
- 11:47say button. mouse button oneclick colon connect function open parentheses close parenthesis and
- 11:57so this is basically going to to fire whenever we click on the button but clicking can also refer
- 12:04to tapping on the button or using right trigger on the the button so we will say print button
- 12:12has been activated so let's go into the game hit test and hit play and so there should be three
- 12:19things happening with this button so first thing is entering into the button oh sorry uh entering
- 12:26into the button Letting Go the button so just like going off screen from the button it'll print both
- 12:33player has entered the button and also player has left the button if we also click on it we
- 12:38can see that button has been activated so that seems to work out pretty well as well so I'm
- 12:43on I'm on PC and this is only running when I'm using the left Mouse button and not the right
- 12:49Mouse if I try clicking on my right Mouse it's not going to activate because Mouse button one
- 12:55click is specifically for the left Mouse button but if we want to to do it for the right Mouse
- 12:59button we would use an event called Mouse button to click so we can just copy this by selecting
- 13:06this and controlling Z and then dropping two lines and hitting control+ V for pasting and
- 13:10we can change Mouse button one click to Mouse button two click so now we're going to print
- 13:15here by saying button has been right clicked and we could just get rid of this activated part so
- 13:23this is going to happen when we rightclick on the button now we have two cases of when we left click
- 13:29on it and when we right click on it it'll print two different things now you kind of have to be
- 13:35careful with mouse button to click because I'm pretty sure Mouse button to click does not work
- 13:41on mobile nor does it work on Xbox or Playstation this is only a PC exclusive event that's why I
- 13:48generally prefer not using Mouse button to click but there may be certain circumstances if you're
- 13:54specifically playing a PC game on Roblox you might use Mouse button to click we're mostly interested
- 14:00in Mouse button one click cuz this is definitely used way more than Mouse button two click all
- 14:05right but now let's do something fancy I'm going to create a prompt for this button every time we
- 14:11press it through a table full of dialogue options that we can choose from so how we're going to do
- 14:16that is we're going to go back to our local script and we're going to make this happen every time we
- 14:22left Mouse click the button so first thing we'll do is we'll create a table full of prompts so
- 14:29after we make reference to our button let's drop two lines and then we'll make a table so we'll
- 14:34call this table phrases and we're going to make this into a table with the open and close curly
- 14:40brackets and then we're going to drop a line so that we can write a phrase for each line to make
- 14:45it more readable so these phrases are going to be strings because we're going to update the buttons
- 14:52text whenever we press it so let's make the first phrase something like ow that hurt or something uh
- 15:00and then we'll write a comma to make another phrase down here so we're going to say stop
- 15:09clicking on me and then we can make another one probably saying don't do that and then we can just
- 15:16make another one by saying this makes me mad and so you you kind of get the idea so these are going
- 15:22to be all the phrases um that will potentially be said in our text so so now need to figure out how
- 15:29we can pick a random phrase from this phrases table so down here after Mouse button one click
- 15:34we're first going to pick a random number uh from one to however many entries there are in this
- 15:40table because we're trying to pick the index uh of whatever we're trying to fetch from this phrases
- 15:46table so we'll say local random index equals math. random and our minimum value is going to be one
- 15:55because the first entry will have a position of one and the last entry is at position four so
- 16:00we'll say math. random 1 to4 now there is another way of picking out our maximum value instead of
- 16:05hardcoding the number four because we might add a fifth entry in the future or maybe even more
- 16:11entries so what we can do instead is that we can fetch the number of entries that our table phrases
- 16:18have by saying the hashtag or pound symbol uh and then the table so our table is phrases so
- 16:26this will return the number of Entry from our phrases table because this acts as the maximum
- 16:33position uh inside of our phrases so basically the position of this one down here so it's going
- 16:39to start at one which is up here and then the last one which is down here so now we have a
- 16:44random index let's actually get that phrase so we'll say local random phrase equals phrases and
- 16:52then if you remember how indexing works if you watched my uh beginners tutorial guide is that
- 16:58we do do the hard brackets the open and close hard brackets and we put in our random index
- 17:03that we picked out so this will essentially be our actual a random phrase so it can be this one
- 17:08it can be this one or even this one or this one so now let's take that phrase and put that inside
- 17:14of the button's text so down here we're going to say button. text equals random phrase all right
- 17:22so now that we have that let's test the game all right so I'm joined into the game if we hover over
- 17:26the button we should see that it's printed in the output now let's click on it we can see that uh a
- 17:31random phrase was picked from our phrases table to then update the text here by saying don't do
- 17:37that if we click it again it'll say don't do that again if we click it again or again yeah and then
- 17:42now it says something different this makes me mad and then we press it again don't do that don't do
- 17:47that don't do that don't do that don't do that and it would say ow that hurts so it's basically just
- 17:51picking a random phrase and updating the text of this button to say whatever that random phrase is
- 17:57so we can just keep on doing this this and it'll just constantly pick a random uh text to update
- 18:04this text button so I figured that was something pretty cool to add all right so for this last part
- 18:07of the video I'm actually going to have you do a challenge and this challenge will have a couple
- 18:13requirements that I want you to follow now again uh you can try this Challenge on your own and then
- 18:17come back and see what I do or you could just simply follow along what I do just to get the
- 18:21experience so essentially what I want you to do is create a prompt right here that basically asks
- 18:28the question do you like Roblox and you could probably guess that this is going to be a text
- 18:33label so I want you to create a text label that asks that question and I want you to create two
- 18:39buttons that acts as a yes button and a no button so you'll have one button that's associated with
- 18:44yes and then one that Associates with no and what I want you to do is when you click on one of them
- 18:51I want you to change the text of the text label to something you think the text will say after
- 18:57picking the option and I also want you to change the background color of the text label as well uh
- 19:03based on the answer that that you picked so for instance if you picked yes then you can probably
- 19:07change the color to green or if you say no then you can change the color to red or something so
- 19:13let's get started on that all right so on the right side let's first create a text label
- 19:18uh text label and we're going to call this text label prompt label let's move this to the center
- 19:27a little bit and let's change the scale of it as well uh just to see the text better let's go down
- 19:32here and press text scaled and let's change the text to The Prompt which was do you like Roblox
- 19:41question mark uh and then let's create two buttons uh so we'll make this our first button so so let's
- 19:47rename this to yes button and let's duplicate it and call this one no button and let's move
- 19:56the no button to the right side and let's let's move the yes button to the left side so in order
- 20:00to differentiate between these buttons I'm going to change the background color of both of these
- 20:05so for the green one let's make it green and then for the no button let's make the background color
- 20:10uh red and let's also change the text for them as well so this one's going to say no for the text
- 20:17and this one is going to say yes for the text it is kind of off-centered a little bit um I'm
- 20:21not very good with symmetry just by eyeballing it so it's like it goes some something like this so
- 20:29now what we'll do is we'll go to our local script uh let's actually delete all this code right here
- 20:34except for our Mouse button one click cuz we don't really need this anymore so let's delete all this
- 20:38let's even delete all the code that's inside of our Mouse button one click and let's re-reference
- 20:44our yes and no buttons so let's delete this and we're going to reference both our yes and
- 20:49no buttons so we'll say local yes button equals gy. yes button and down here we'll say local no
- 20:56button equals g guy. no button and then we'll also make reference to our prompt label so we'll say
- 21:03local prompt equals guy. prompt label so now what we'll do is we'll create two mouse button oneclick
- 21:10events for both yes and no buttons so for this one this is going to be for the yes button let's
- 21:16copy this put it down here and this one's going to be for the no button and then what we'll do is
- 21:20we will first change the background color of the prompt so we will say prompt. backgroundcolor 3
- 21:28equals color 3. from RGB and then uh let's pick a color that's associated with picking yes so we'll
- 21:38probably pick a green color and we can do that by selecting these parameters and then clicking this
- 21:42color wheel right here to pull up the panel so we'll make it green and then we will copy this
- 21:49and put it down here and instead of it being green let's change this to Red for no and so down here
- 21:56let's change the text of the prompt by saying prompt. text equals uh maybe something like yay
- 22:05I'm glad you like Roblox as well and then we can just like do a little something like that uh and
- 22:13then we can pretty much just do the same thing down here with no by saying a I'm sorry to hear
- 22:21that or something like that it seems a little basic but I just want you to get the gist of
- 22:26these text buttons when we're using these events so I think we're pretty much done let's just go
- 22:31to test and hit play and see our change so we're loaded into the game uh if I press yes then the
- 22:38text label should change by saying yay I'm glad you like Roblox as well and the background color
- 22:43of this text label Chang to Green if we say no then the background color changes to red and the
- 22:49text changes by saying a I'm sorry to hear that and we can just kind of repeatedly do this over
- 22:54and over again um there isn't really anything too special happening with these text buttons or text
- 22:59labels so that's pretty much all I wanted you to do for this challenge it's pretty simple but just
- 23:03getting a feel for these GUI elements the more you practice them I think will definitely help
- 23:08you when you try to implement more complicated GUI elements inside of your Roblox game so that's
- 23:14pretty much going to be it for this episode we un covered quite a bit on this tutorial in the
- 23:17next episode I'm going to be covering over misconceptions with sizing and positioning
- 23:22and also scaling and offset issues so that one's definitely going to be a very valuable episode for
- 23:27you to tune into uh so I'm looking forward to that but in the meantime I'm going to revert back to
- 23:33my Advanced scripting tutorial guide so that I can make videos on that tutorial and make it alongside
- 23:39this one as well so that you can follow along with both guides and get the best out of both
- 23:47tutorial guides as we go through them so that's pretty much going to be it for this episode join
- 23:51my Discord server the link is in the description and I will see you in the next episode take care
About this transcript
This page contains the full transcript of TextButton - Roblox GUI Tutorial #3 by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 4,624 words across 240 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.