Music GUI
Local Script
local frame = script.Parent
local scrFrame = frame.ScrollingFrame
local music = frame.Music
local current = frame.Current
local volumeBar = frame.VolumeBar.VolumeGreen
local volumeUp = frame.VolumeUp
local volumeDown = frame.VolumeDown
local musicButton = frame.Parent.MusicButton
local stop = frame.Stop
local playing
frame.Visible = false
current.Text = "Currently Playing:"
local function playMusic(sound)
if playing then
playing:Stop()
end
sound:Play()
playing = sound
playing.Volume = tonumber(volumeBar.Text) / 100
end
volumeUp.MouseButton1Click:Connect(function()
if playing then
if playing.Volume < 1 then
playing.Volume += 0.1
end
volumeBar.Size = UDim2.new(playing.Volume, 0, 1, 0)
volumeBar.Text = math.floor(playing.Volume * 100 + 0.5)
end
end)
volumeDown.MouseButton1Click:Connect(function()
if playing then
if playing.Volume > 0 then
playing.Volume -= 0.1
end
volumeBar.Size = UDim2.new(playing.Volume, 0, 1, 0)
volumeBar.Text = math.floor(playing.Volume * 100 + 0.5)
end
end)
stop.MouseButton1Click:Connect(function()
if playing then
playing:Stop()
current.Text = "Currently Playing: "
end
end)
musicButton.MouseButton1Click:Connect(function()
frame.Visible = not frame.Visible
end)
for _, song in pairs(music:GetChildren()) do
local track = Instance.new("TextButton")
track.Parent = scrFrame
track.Text = song.Name
track.Font = Enum.Font.PatrickHand
track.TextScaled = true
track.MouseButton1Click:Connect(function()
current.Text = "Currently Playing: "..track.Text
playMusic(music[track.Text])
end)
end
Local Script - Better Scaling
UIGridLayout - CellSize
{1, 0},{0, 50}
50 is adjustable up or down to control height of buttons
local frame = script.Parent
local scrFrame = frame.ScrollingFrame
local music = frame.Music
local current = frame.Current
local volumeBar = frame.VolumeBar.VolumeGreen
local volumeUp = frame.VolumeUp
local volumeDown = frame.VolumeDown
local stop = frame.Stop
local musicButton = frame.Parent.MusicButton
local playing
frame.Visible = false
current.Text = "Currently Playing:"
musicButton.MouseButton1Click:Connect(function()
frame.Visible = not frame.Visible
end)
local function playMusic(sound)
if playing then
playing:Stop()
end
sound:Play()
playing = sound
playing.Volume = tonumber(volumeBar.Text) / 100
end
volumeUp.MouseButton1Click:Connect(function()
if playing then
if playing.Volume < 1 then
playing.Volume += 0.1
end
volumeBar.Size = UDim2.new(playing.Volume, 0, 1, 0)
volumeBar.Text = math.floor(playing.Volume * 100 + 0.5)
end
end)
volumeDown.MouseButton1Click:Connect(function()
if playing then
if playing.Volume > 0 then
playing.Volume -= 0.1
end
volumeBar.Size = UDim2.new(playing.Volume, 0, 1, 0)
volumeBar.Text = math.floor(playing.Volume * 100 + 0.5)
end
end)
stop.MouseButton1Click:Connect(function()
if playing then
playing:Stop()
current.Text = "Currently Playing:"
end
end)
for _, song in pairs(music:GetChildren()) do
local track = Instance.new("TextButton")
track.Parent = scrFrame
track.Text = song.Name
track.Font = Enum.Font.PatrickHand
track.TextScaled = true
track.MouseButton1Click:Connect(function()
current.Text = "Currently Playing: "..track.Text
playMusic(music[track.Text])
end)
end
--New lines for auto scaling canvas
local absoluteSize = scrFrame.UIGridLayout.AbsoluteContentSize
scrFrame.CanvasSize = UDim2.new(0, absoluteSize.X, 0, absoluteSize.Y)