I have been trying to fix this for a while, but I can’t find out why it is not working.
Here is the full script:
local Playing = true
local Music = {
{'rbxassetid://1840202507', 1, 'Drifting Star'},
{'rbxassetid://187918023', 2, 'Relaxing Music... :)'}
}
script.Parent.PlayButton.MouseButton1Click:Connect(function()
print(tostring(Playing))
if Playing == false then
Playing = true
script.Parent.PlayButton.Image = 'rbxassetid://3192517628'
script.Parent.Music:Play()
elseif Playing == true then
Playing = false
script.Parent.PlayButton.Image = 'rbxassetid://8215093320'
script.Parent.Music:Stop()
end
end)
local Song = math.random(1, #Music)
while wait(0.5) do
pcall(function()
if script.Parent.Music.SoundId ~= Music[Song][1] then
script.Parent.Music.SoundId = Music[Song][1]
script.Parent.Music.Volume = Music[Song][2]
script.Parent.Music:Play()
end
if script.Parent.Music.TimePosition >= script.Parent.Music.TimeLength then
if Song > #Music then
Song = 1
else
Song = Song + 1
end
end
script.Parent.SongName.Text = tostring(Music[Song][3])
script.Parent.Length.Text = tostring(script.Parent.Music.TimePosition)..' / '..tostring(script.Parent.Music.TimeLength)
end)
end
while wait(0.5) do
pcall(function()
if script.Parent.Music.SoundId ~= Music[Song][1] then
script.Parent.Music.SoundId = Music[Song][1]
script.Parent.Music.Volume = Music[Song][2]
script.Parent.Music:Play()
local Frame = script.Parent
local Button = Frame.PlayButton
local Music = Frame.Music
local SongName = Frame.SongName
local Length = Frame.Length
local Musics = {
{'rbxassetid://1840202507', 'Drifting Star'},
{'rbxassetid://187918023', 'Relaxing Music... :)'}
}
local Playing = false
Button.MouseButton1Click:Connect(function()
if not Playing then
Playing = true
Button.Image = 'rbxassetid://3192517628'
Music:Play()
elseif Playing then
Playing = false
Button.Image = 'rbxassetid://8215093320'
Music:Stop()
end
end)
task.spawn(function()
while task.wait() do
local Song = math.random(1, #Musics)
SongName.Text = tostring(Musics[Song][2])
Music.SoundId = Music[Song][1]
if not Music.IsLoaded then
Music.Loaded:Wait()
end
Music:Play()
task.spawn(function()
while Music.TimePosition < Music.TimeLength do
task.wait()
Length.Text = tostring(Music.TimePosition)..' / '..tostring(Music.TimeLength)
end
end)
Music.Ended:Wait()
end
end)