How to Make a Music Player GUI

I no longer suggest using my tutorial as it is buggy. I recommend using this persons one instead:

Old post

Hello there!

Today I’m going to show you how to make your very own, Music Player GUI! (As you could guess from the title) It includes a progress bar, a mute button and more! (See reference image below) So lets get started!

First, you’ll need to create a new ScreenGui in StarterGui, name it MusicGui, then insert a Frame, scale it how you want. Inside the Frame, create two more Frames, one called Background and one called OverlayFrame. Make these both the same size and a long thin rectangle shape and make sure the OverlayFrame is on top of the Background frame. To do this, change the index of the OverlayFrame to 2.
Now create two TextLabels and position them like in the image below.


You can start to change the colours of it as we go along.
Name the top one NowPlaying and name the bottom one SongName. You don’t need text for SongName but in NowPlaying, change the text to Now Playing:.

I know this might be getting a bit boring so I’m going to try to make you more awake with this BIG text.

Feeling awake now? Good! :+1:
Now inside the OverlayFrame, create another frame called ProgressBar and scale it to {1, 0},{1, 0} so it covers the whole of the OverlayFrame. Then insert a LocalScript inside the ProgressBar. So your Explorer should look something like this:
Screenshot 2021-05-21 at 20.17.43

Inside the LocalScript, paste the following text in;

local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local MusicProgress = PlayerGui.MusicGui.Frame
local Songs = game.Workspace.Sounds

RunService.RenderStepped:Connect(function()
	for _, Song in pairs(Songs:GetChildren()) do
		if Song:IsA("Sound") and Song.IsPlaying == true then
			MusicProgress.SongName.Text = Song.Name
			local Progress = Song.TimePosition / Song.TimeLength
			MusicProgress.OverlayFrame.ProgressBar.Size = UDim2.new(Progress, 0, 1, 0)
		end
	end
end)

We’re almost done, hang in there!

Next, insert a Folder into Workspace and name it Sounds. Create a Script and name it SoundManager and paste the following text in;

local Songs = game.Workspace.Sounds:GetChildren()

while true do
	local RandomSong = Songs[math.random(1, #Songs)]

	if RandomSong:IsA("Sound") then
		RandomSong:Play()
		RandomSong.Ended:Wait()
		RandomSong:Stop()
	end
end

Then go into your toolbox and find some audio’s, choose which ones you’d like and insert them into the folder or go to the Roblox Library and copy the ID’s of the audio’s you’d like.
This is what your Explorer will look a bit like:

Sorry, almost forgot the mute button! Create a new ImageButton inside the main Frame and name it MuteButton. Change the Image to http://www.roblox.com/asset/?id=6664390892. Then insert a LocalScript inside it. Copy and paste this text into it;

local Songs = game.Workspace.Sounds

local mute = false

script.Parent.MouseButton1Click:Connect(function()
	for _, Song in pairs(Songs:GetChildren()) do
		if Song:IsA("Sound") then 
			Song.Volume = mute and 0.5 or 0
		end
	end
	script.Parent.Image = mute and "rbxassetid://6664390892" or "rbxassetid://6664391914"
	mute = not mute
end)

And that should be you done!

If you think I have missed anything out or it isn’t working for you, send me a reply on this post!

But if you are too lazy and honestly I feel you because sometimes I get pretty lazy and creating this actually took me quite a bit of time so you can go ahead and download this Music Player GUI below!
Music Player GUI.rbxm (9.6 KB)
Or you can get it off the Roblox library!
https://www.roblox.com/library/7850640503/Music-Player-GUI

I’m sorry if I didn’t do a good job at explaining this but this is my first forum tutorial so tell me how I did!

Special Thanks:
xXxLoILPxXx (@ShyFlooo)
deafaultyboii1324 (@deafaultyboii1324)
Jackscarlett (@Jackscarlett)
Afrxzo (@Afrxzo)
EmbatTheHybrid (@EmbatTheHybrid)
LucasTutoriaisSaimo (@LucasTutoriaisSaimo)
sworded333 (@sworded333)
AmitRoblox1987 (@AmitRoblox1987)
FlabbyBoiii (@FlabbyBoiii)

15 Likes

I wouldn’t say this is a tutorial moreso than it is a bunch of code dumped into a thread connected by directing people where to copy-paste it into.

I think it would be infinitely more helpful if you explained the concepts behind creating a music player and ease developers into the code by explaining what each part does. It’s helpful to have people write their own code, not to have them copy-paste things in without a sufficient understanding of what the pieces they’re putting together are doing.

That being said, even the code itself could use some work. It helps to be more knowledgeable on both code and the topic you’re trying to teach, lest you be teaching bad habits or wrong information.

The first problem is the hierarchy and how it’s affecting your code. You’ve chosen to bury it deep in the Gui rather than making it an immediate child of the ScreenGui. This isn’t a bad problem per se but it’d be easier for the sake of organisation to put it higher up in the hierarchy. However, the code produced by this makes it bad because now you’re unnecessarily accessing PlayerGui to get the Gui. The LocalScript is still in the Gui so you can just define elements relative to the script.

The next issue is that you’re connecting the update to RenderStepped. Rule of thumb is to never use RenderStepped unless you’re making an update that needs to occur before the frame renders - this mostly pertains to the camera and the character. No reason why you should be using it otherwise, settle for Heartbeat. Seems appropriate enough to update it after everything else in the frame is done.

Another issue is that your entire system is bad on memory. Sounds consume a considerable amount of memory unbeknownst to a lot of developers and simply having them lying around occupies a significant amount of memory, sometimes bloating the entire memory use up to a few GB. You should instead opt to teach users how to build a memory-friendly system that uses a single sound instance and stores music ids preferably in a ModuleScript that can be cycled through.

Because of the above issue, this also makes the code running in your RunService connection bad since every frame it will iterate over an arbitrary number of instances searching for the one that’s playing before updating, which in itself is pretty unnecessary. Using a single sound instance you can track the properties of the Sound object and pull relevant data from a ModuleScript (e.g. track name). No looping every frame which’ll get worse if the developer adds many tracks.

Next issue is that your server-side script is done poorly. The canonical placement of scripts is now ServerScriptService so scripts in Workspace is a fairly outdated practice unless you have good reason for that happening (e.g. script must be a descendant of the Workspace or you’re using Actors). You’ve also dodged the issue of catching the script in the Sounds folder by doing nothing if the current iteration sees that math.random selected the Script’s indice… could just not put the script there at all.

Final issue is your mute button. Although I strongly discourage using more than one Sound instance for a music player system, in its current state where it uses multiple your mute button is doing more work than it needs to. Opt to use a SoundGroup instead and assign the SoundGroup property of all sounds in the folder to this SoundGroup. From there, your mute button simply needs to configure the volume of the SoundGroup and all sounds will adhere to that new volume (SoundGroup.Volume is multiplicative). No loops needed.

It’s a good start but it does need work. I encourage you to get feedback on your systems via the support categories and polish up your knowledge before taking on writing a tutorial. :slight_smile:

PS: Special thanks can be written as just usernames. No need to mass mention.

4 Likes

Hello colbert2677, thank you for the feedback! I understand there are things I can do to make it work smoother and I’ve gotten feedback from a couple of people already and posted the following topics:

My goal is for this to be my first YouTube tutorial so if you could help me make it better that would be amazing! I’ve only been a Roblox developer for just over 1 year and I’m always learning!

This is nice and I’m trying to make a sleek design with this system, but I have an issue. The progress bar isn’t the same for every song so sometimes it goes past the UI or doesn’t get to the length I want it at.

image

You’ll have to alter the script a bit

At this bit :arrow_up: change the last three to your sizes but not the one that says Progress.

It is still ending up in the exact same spot for some reason.

I’m not really sure what’s wrong then… :thinking:
I don’t really work with GUI’s that often, sorry.