Transcription
ooh free tacos! I am quite hungry. Oh no.
[Music]
Okay, okay. You might ask, what the heck that was about? That was pretty much my introduction to what we're going to be talking about in this episode, which is going to be sounds and sound groups. And so, in any video game you can think of, not even just Roblox, but any video game, sound design is one of the most important aspects to a video game because it enhances the gameplay experience for everybody that's playing the game. Like, imagine the example that I just showed you like 30 seconds ago. Without any sounds, it would probably sound less cringe, sure, but those sounds are able to amplify the gameplay experience for everybody that's playing the game. And so, that's what I'm going to be showing you how to do inside of this episode. So, with that being said, let's jump straight into the episode.
All right, let's think about this for a minute. Now that we know sounds exist, where do we find these sounds, or in this case, audio? Well, there's two places of finding these sounds. And the first one is from the Roblox website itself, in the creators tab. But I'm going to be showing you the second way of finding these audio, and that is from the toolbox. If you don't remember where the toolbox is, there's two ways of finding it. So, the first one is if you go to home, there should be this toolbox button under the insert category. If we click that, then we should see a toolbox popup that shows us a whole, whole bunch of community-created resources that we can implement straight into our Roblox game. The second place to find this is by going to view and then clicking on the toolbox button that shows right here.
I mentioned this previously when I introduced the toolbox. You should generally not use this toolbox because there's a lot of backdoor scripts in a lot of these community-created assets. So, I would be very cautious implementing these inside of your Roblox game. But for the sake of this tutorial, we'll be using it. So, to find these audio, we have to click on this drop-down that says models, and we should see a tab called audio. If we click that, then we should see two different tabs that show sound effects and music. So, in this case, what we're going to do is just go through these entries and pick out which one seems the best to us. So, by each of these, we can click this play button to test out the audio before inserting it into our game. So, let's hit this.
Okay, so this is a simple rain sound effect. Let's try the second one. Okay, so this one sounds like a... this, this one sounds like pretty good music. Um, well, this is in the sound effects category, so it doesn't really make sense. Uh, but yeah, this sound effect or music, in this case, sounds pretty good. So, how do we insert it? Well, we just simply hit this insert button, and this will insert it straight into our workspace, and it comes in an instance called a sound. So, this is pretty much what it looks like. And down here in the properties, we can see that we can preview this sound effect just by clicking on this play button, and this is to let us know that the sound is actually working properly.
So, now it just comes down to implementing it through our scripts. So, there's an important property I want you to understand first, and that is this property called sound ID. And it's pretty much a string that basically has a URL of RBX asset ID colon, uh, 24 dashes, and then you have this big number right here at the end of it. This is essentially a unique ID to this specific audio that we just pulled out, which is this, uh, song that we pulled from the audio library. So, if we change this number to a different number that's also an ID for another sound, then it'll change our sound object to that new sound. So, for instance, let's take another sound, uh, just like something completely random. Uh, let's insert this one. This one is called nightmare yelling bursts of distorted something. I don't even know what that says by the end of it. But as you can see with this sound ID, the URL is the same, but what's different is the number. So, this one is like 912 something something something 501. This one is 9125 something something something 017. So, these have a different ID from each other, letting you know that this is the sound for whatever this sound is on the Roblox website. So, that's something I wanted you to know about.
There's a bunch of other properties here, like in this playback category that shows looped, playback speed, time position, and volume. So, let me give you a quick rundown of each of these. So, looped basically means that when the sound finishes, when it reaches the end of its time length, then it's just simply going to play the sound again from the beginning. So, if I have this selected and I just play this, then by the end, it should automatically restart. Playback speed is basically how fast the audio is playing. So, if I set this to two, then it should double the speed of the playback speed. And by default, the number is just one. Time position is where in the audio you want to start. And finally, we have volume, which obviously, it's how loud or how soft the audio is when you play it. So, 0.5 is the default, but a lot of sound effects, I know developers use, is usually at volume one, but that really depends on your preference. So, that was just a quick rundown of some of the sound properties we might use inside of our Roblox games.
Now, let's get to playing these sound effects inside of our game. So, on the right side, let's rename our sound to test music. And then let's add in a script inside of workspace. So, let's insert a script. And let's first make reference to our sound. So, we'll say, local music equals script.parent.test music. And there's basically four methods or functions that I want to teach you with sounds. And the first one's going to actually play the sound. So, we're going to simply just say, music:Play(). And that's literally it. It's just one simple line. So, if I go and hit test, as soon as we join into the game, then the sound should be playing.
So, there you go. As soon as we joined in the game, the script made the sound play, and it's going to keep on playing until it reaches the end of the sound, and then it's going to stop, unless we have loop turned on, which in this case, we don't. So, if at any certain point we want to pause the music, we would just drop a line down here, and we would simply just say, music:Pause(). And we can add in a task.wait() here for like about 3 seconds for it to just pause. And when we pause it, we can also resume it too. So, let's add in another task.wait() of 2 seconds and put in, music:Resume(). To continue where it left off. And then finally, at the end, we could just stop it completely by saying, task.wait() uh, about maybe 5 seconds, and then we'll say, music:Stop(). So, this will just completely stop the music, and it'll make the time position go back to the beginning, so that we'll wait for the next time that we call, uh, music:Play().
So, now let's test the game. So, what should happen is about in about 3 seconds, it'll pause the sound, and then it'll resume it, and then stop it. Yeah, so it paused, and then it resumed. So, now after a little bit, it should completely stop it. All right, and there we go. So, now we've successfully been able to play our sounds, we've been able to pause it, resume it, and even stop it. So, those are all the methods provided to us with sounds on Roblox.
Now, you might have questions about the audio that just played. Who is it being played to? How far can you hear this sound? This is a concept with Roblox sounds that I'm going to be calling global and local sounds. So, pretty much what you just heard was a global sound because we had a script inside of workspace play the sound as soon as the game started up. So, everybody inside of the game, so every player, no matter when they join the game, they will hear the same part of the sound wherever they are, and with whatever property the sound has. So, if we were in the first 30 seconds of the sound, then all players are going to be hearing that specific part of the sound. If it's at volume two, they're going to hear it at volume two. And if it's at playback speed two, then they're also going to hear that. So, that's pretty much what global sound is.
But now you might wonder, how do we play a sound for a specific player? This is actually relatively easy. What we can do is put in a sound inside of any property that's only local to the player, like StarterGui, StarterPack, StarterPlayer. Just insert sounds in there and have a local script play that sound. So, let's take StarterGui for example. So, I'm going to take this music and put it inside of StarterGui. And I'm also going to disable the script since we're not going to use it anymore. Let's create a new local script inside of StarterGui. And let's make reference to our test music. So, we're going to say, local music equals script.parent.test music. Now, what we'll do is we'll just simply say, music:Play(). Just like before. Now, let's go into the game, hit test, and hit play. See what happens. It's kind of hard to tell the difference, but trust me when I say that this is, that this is being played on the local player whenever the player has joined the game for the first time. So, meaning, in about 30 seconds, if another player joins the game, they're going to be hearing the sound from the beginning, and not where I currently am with the sound. So, the sound is pretty much going to be located inside of our player GUI, and this is where it's going to be played. So, this is the most common place you would see local sounds. It would usually be inside of your player GUI because if you had like a GUI shop or any sort of UI interface that plays a sound whenever you open it up or interact with it, then it's usually going to be played inside of StarterGui, or just any local sound period, it's going to be played inside of player GUI.
We now understand global sounds. We also now understand local sounds. But there's also another type of sound that I would like to call proximity sounds. And these are basically sounds that can be heard from a specific part of the game. Where the closer you are to that part, the louder the sound is. But the farther you wait, the farther away you are from that part, the quieter it gets. So, I think you've seen many examples of this in, in Roblox games before. So, I think you know what I'm talking about. But if I just insert a part, and let's say there was a sound that was coming out of this part specifically, the closer I walk up to it, the louder it gets. But then the farther away the character goes, the quieter the sound is going to get until it's barely audible anymore. So, this is what I call, so this is what I like to call proximity sounds. And that's what we're going to do for this part. So, let's find a new sound. Let's go to view and toolbox. Let's just search up bubble and see what comes up. Okay, yeah, it's a little quiet, but I think it works. So, let's hit insert. Oh, yeah, and by the way, whatever instance you're selecting inside of the Explorer, whether that would be Workspace, ReplicatedStorage, or just a specific part, if you have it selected and you insert something from the toolbox, it'll automatically set its, uh, it'll automatically set its parent to whatever you selected. So, I think that's something very useful to know about.
Okay, but let's rename this sound to something that's easier to reference. So, let's just call this Bubbles. And let's insert another script. So, let's make reference to our sound by saying, local bubbles equals script.parent.Bubbles. And let's just simply play it. Bubbles:Play(). We might also make the volume a little bit higher too, so we can hear it better. So, let's say, bubbles.volume equals 2. And let's also make it a looped sound effect as well. So, we're going to say, bubbles.looped equals true. All right, so now let's go into the game and see, and see our result.
All right, and as you can see, we can hear the sound coming specifically from this part. And if we walk farther away from it, we're going to hear the part less and less. And so, yeah, the farther away we're walking from this part, the less audible this sound is going to be. But the further we walk, walk up close to it, then we're going to be hearing the sound yet again. So, we're going to be walking up just a little bit closer, and now we hear the sound again. So, this basically works as intended. Our proximity sound effect is perfectly capable.
We were able to successfully create the sounds we want to create inside of our Roblox games and implement them. But what if, let's say, we had multiple different sounds that we wanted to play back to back, and they also had a whole bunch of different properties that we wish we could just change within one sort of instance, like, let's say volume? What if we wanted the volume to consistently be one throughout the entire thing, and we want to, and whatever sound we're playing through this group or category, uh, we'll just stop the whole thing entirely, and then play it again once we want it to play again? So, one big example I can think of is music in general. So, if you have a whole bunch of sounds that are inside of a music category, and let's say during specific parts of the game you want to play the music, then you can play the music. And if you want to just completely cut off all the music, then you would do that using a group. Or if you have like a toggle option inside of settings where you want the music to be completely off, then no music is going to be playing. All of this can pretty much be done using an instance called a sound group. And let me show you what that looks like.
So, where would we usually, so where would we put the sound group? We would usually put it inside of a new service called SoundService. And this pretty much handles, uh, all the sounds that are generally being played inside of, inside of your Roblox game. But I've seen successful games that don't use SoundService, so you don't have to use this, but it is, but it is quite helpful because it shows a bunch of properties that have to do with manipulating general sounds inside of your game. Uh, but for the purpose of this episode, we're going to make a new sound group. So, let's hit the plus sign and let's insert a sound group. So, this is what the sound group looks like. And we can probably, and we can pretty much just call this Music. And this only has one property, which is volume. I will get to this version of volume in a little bit. But as of right now, let's add some music inside of SoundService. Uh, I'm, I'm not going to grab actual music for copyright reasons, but let's just insert a bunch of sounds inside of here.
All right, I just inserted a bunch of sounds, uh, into my music folder. And like I said, sound groups aren't really that special. It's basically just, it's basically just a collection of sounds you can put inside of your game to which you can have easier access to specific sounds that you're looking for, and you can modify them accordingly. Um, this will come more in handy when we talk about sound effects, but as of right now, these are all basically placed inside of the same sound group for easy access. So, let's create a local script inside of StarterGui. And let's look for our music sound group. So, we're first going to access our SoundService. So, we're going to say, local soundService equals game:GetService("SoundService"). Now, let's look for our music sound group, which is, local music equals soundService:WaitForChild("Music"). Here's what we're going to do. We're going to play a random sound or music from the sound group. So, let's pick a random number from one to however many sounds that are inside of the sound group. So, let's say, local randomNum equals math.random(1, #music:GetChildren()). Because we're trying to re, we're trying to fetch a table, not an instance. So, now let's go down here and let's actually get that sound. So, we're going to say, local randomSound = music[randomNum]. And now let's play that random sound. RandomSound:Play().
Okay, I made a little typo here. I'm trying to retrieve the music table, not the actual instance when I'm trying to fetch the sound. Uh, this can be more readable just by taking GetChildren() and putting it up here when we're declaring it, that way we don't have to say GetChildren() every time. So, I think this makes it a little bit more readable. Now, let's play the game and see what happens.
Okay, so when we joined in the game, it played the original song. Uh, now let's try playing it again and see, and see if it changes to something different. Okay, and now it's playing something different, which is basically alarm sound effects. Okay, and now it's playing a bunch of static sounds. So, this seems to work as intended. Whenever we join the game, the game is going to automatically pick a sound from the music's group and just play it. I think we pretty much got it to do what we wanted it to do.
Now, there's something interesting I want you to look at. So, if we go back to our sound group, our music group, I mentioned that there's only one property that's called volume. Now, you might ask, what's the difference between this volume and the volume that's inside of an individual sound, like this one? So, if we remember back to what volume is for an individual sound, it's basically how loud or how quiet the sound is when it gets played. So, if it's a volume of zero, obviously you're not going to be able to hear it. So, the default is 0.5, but you can also make it higher, to let's say one, to even as big as 10. So, that's pretty much self-explanatory. But what's sort of confusing about sound group sounds is that this volume changes the volume of every single sound that's inside of the sound group. That part makes sense. But there is something else that trips people up about this sound, about this volume property. This volume does not act as a setter for all of these sounds to just be whatever this volume is. This acts as a multiplier to set the volume of whatever each audio is to amplify it to whatever this sound is. So, let's say we had this sound right here that's volume 0.5. If our multiplier is 0.5, this is effectively saying we should take this volume and make the volume by half. So, 0.5 * 0.5 is 0.25, because a half of 0.5 is 0.25. And let's say we change this volume to one. Zero, 0.5, also known as the half of one, is 0.5. So, that's what this new volume is going to be when you play it. And for other sounds, it could be different. If this volume is two, then the volume of this is going to be one, because half of two is one, since we have this volume multiplier set to 0.5. Now, if we set this volume to two, it's going to double the volume of each individual sound. So, if this is volume one, then the volume of this is going to be two when we play it. If this is two, then the volume is going to be four. And, uh, this one is going to be one, because 0.5 * two is one. So, that's a very distinct feature about sound group volume that I want you to understand, because people do get tripped up by it. So, I, I want to say this one more time. The sound group volume is a multiplier of all these different sounds. It's not a setter for all of these sounds to have the same volume as whatever this sound group volume property is set to.
And for the last part of this episode, episode, I'm going to do a brief introduction to sound effects. I'm not going to go too much into detail with the technicalities, maybe I'll do that in a future episode. But basically, a sound effect is a sound modifier to current sounds or music that you already have inside of your game. So, this can be found inside of our sound groups, and it's convenient to have these in a sound group because we want to change, we want to add a sound effect to every single sound that's inside of a sound group. So, so this is pretty much what it's going to look like. Let's hit the plus sign next to our sound group Music, and we can see that Roblox is suggesting us to add in a whole bunch of different sound effects. So, we have chorus, we have distortion, pitch shift, revert, reverb, echo, and equalizer. But let's say we want to add in a chorus sound effect. Let's add that in, and it's going to be dropped into our sound group alongside our other sounds. So, if we click on this, we can see that there's a bunch of stack here, like depth, min, priority, rate. I'm not going to go over these, but I'm sure the default settings are good enough as of right now. So, it's pretty much as simple as that. All we did was basically add in a sound effect into our sound group alongside our sounds, and it'll automatically put that sound effect inside of these sounds when we play them.
So, let's hit play and see and listen to our new sounds. So, it is kind of hard to notice, but there is a sort of chorus or echoey sound effect to the sound that's being played right now. Let's try a different sound to see if we can hear it better. So, it's, it's hardly noticeable, but there is a very slightly echoey sound effect by the end of the sound that's being played. That's basically a small introduction to sound effects that Roblox has provided for us to manipulate our sounds a little bit. So, I just think it's something pretty useful to have when you're using this alongside sound groups.
So, that's pretty much going to sum up sounds, sound groups, and even sound effects as well. I hope you found this episode to be helpful. This is definitely going to be used very, very, very often. I don't think I really need to say, say anymore. Um, sounds, it's kind of just one of those things you need to have them in your Roblox game. So, I hope that when you watch this video and use this when you're making your Roblox games, you will find this, you will find this tutorial to be helpful to you. And overall, I just think that this is a really nice feature Roblox has added for us because it gives us easy access to audio using their entire audio library to add these sounds and music and just play them whenever we want to. And I just think it's a neat feature to have.
All right, well, that's going to be it for this episode. Join my Discord server, the link is in the description, and I will see you in the next episode. Take care.