Music Player GUI

Recently I made a tutorial explaining How to Make a Music Player GUI, but I was given some poor feedback so I would like some help reviewing my code. I think my mute script is good, but the other two could use some work. This is some code inside a local script that makes the bar move along the GUI:

Local Script
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)

And this is some code inside a script that makes the songs play:

Script
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

I would like to improve it by making it less buggy and overall a lot better. Thank you in advance. :relaxed:

In the main Script, you should check that the random song chosen, isn’t the same as the song previously played.

3 Likes