So I have this script, I believe what it does is self explanatory, all of it works except the part that is changing the bar size, what I mean is as soon as I click the button to play a new sound it instantly registers that the new sound has ended, thus breaking the loop, meanwhile the sound is still playing.
local player = game.Players.LocalPlayer
local open = script.Parent.Open
local back = open.Background
local stop = back.stop
local play = back.playSong
local musicFolder = game.workspace.Music
local playlist = {}
local thing1 = back.Bar
open.MouseButton1Click:Connect(function()
if back.Visible == false then
back.Visible = true
else
back.Visible = false
end
end)
local function playMusic()
local chosenSound = playlist[math.random(1, #playlist)]
chosenSound:Play()
back.songName.Text = tostring(chosenSound)
back.SoundID.Text = tostring(chosenSound.SoundId)
stop.MouseButton1Click:Connect(function()
chosenSound:Stop()
back.songName.Text = "Nothing is currently playing"
back.SoundID.Text = ""
end)
play.MouseButton1Click:Connect(function()
chosenSound:Stop()
end)
repeat wait()
print(chosenSound)
thing1.Size = UDim2.new(0.2,0,chosenSound.PlaybackLoudness/-1000,0)
until chosenSound.Ended
print(tostring(chosenSound).. ' Ended')
chosenSound.Ended:Wait()
chosenSound:Stop()
playMusic()
end
for i, sound in pairs(musicFolder:GetChildren()) do
table.insert(playlist, sound)
end
play.MouseButton1Click:Connect(function()
playMusic()
end)
I have fixed it myself here is the functional code:
local player = game.Players.LocalPlayer
local open = script.Parent.Open
local back = open.Background
local stop = back.stop
local play = back.playSong
local musicFolder = game.workspace.Music
local playlist = {}
local thing1 = back.Bar
open.MouseButton1Click:Connect(function()
if back.Visible == false then
back.Visible = true
else
back.Visible = false
end
end)
local function playMusic()
local chosenSound = playlist[math.random(1, #playlist)]
chosenSound:Play()
back.songName.Text = tostring(chosenSound)
back.SoundID.Text = tostring(chosenSound.SoundId)
stop.MouseButton1Click:Connect(function()
chosenSound:Stop()
back.songName.Text = "Nothing is currently playing"
back.SoundID.Text = ""
end)
play.MouseButton1Click:Connect(function()
print("stopped sound: "..tostring(chosenSound))
chosenSound:Stop()
end)
repeat task.wait()
print(chosenSound)
thing1.Size = UDim2.new(0.2,0,chosenSound.PlaybackLoudness/-1000,0)
until chosenSound.IsPlaying == false
print(tostring(chosenSound).. ' Ended')
chosenSound.Ended:Wait()
chosenSound:Stop()
playMusic()
end
for i, sound in pairs(musicFolder:GetChildren()) do
table.insert(playlist, sound)
end
play.MouseButton1Click:Connect(function()
playMusic()
end)