Hi!
Recently I changed my music script to offer more, and add new UI.
I now have some problems with it.
First, when it DOES work, the little popup says the name of the last song played.
Second, it seems to not play the next some. Never, only when I make the attribute false, then true again will it start playing.
Also, probably because of the not playing issue or out of date track, the UI does not update anymore.
And lastly, the mute button does not work.
Code:
local function Play()
if not Player:GetAttribute("PlayMusic") then return end
if Player:GetAttribute("PlayMusic") == false then return end
if PlayingTrack then PlayingTrack:Stop() end
randomTrack = availableMusic[math.random(1,#availableMusic)]
if SecretChance == 472793 then
local availablesecrets = game.ReplicatedStorage.SecretSongs:GetChildren()
local randsecret = availablesecrets[math.random(1,#availablesecrets)]
randomTrack = randsecret
end
Player:SetAttribute("CurrentTrack",randomTrack.Name)
-- if randomTrack.Name == "SecretSongs" then randomTrack = availableMusic[math.random(1,#availableMusic)] return end
PlayingTrack = randomTrack
PlayingTrack.Volume = NextVolume
randomTrack:Play()
playing = true
PlayingSong = PlayingTrack
--print ("Playing", randomTrack.Name)
SecretChance = math.random(1,999999)
while playing == true do
PlayingUI.Parent.ea.time.Text = math.round(PlayingTrack.TimePosition).."/"..math.round(PlayingTrack.TimeLength)
PlayingUI.time.Text = math.round(PlayingTrack.TimePosition).."/"..math.round(PlayingTrack.TimeLength)
task.wait()
end
end
Player:GetAttributeChangedSignal("PlayMusic"):Connect(function()
Play()
end)
local function ToggleMusic()
if Player:GetAttribute("PlayMusic") then
Player:SetAttribute("PlayMusic",false)
else
Player:SetAttribute("PlayMusic",true)
end
end
repeat task.wait() until randomTrack ~= nil
randomTrack.Ended:Connect(function()
PlayingUI.Parent.ea:TweenPosition(UDim2.new(-0.009, 0, .723, 0), "In", "Quint", 1.5, true)
PlayingUI.Parent.ea.name.Text = randomTrack.Name
Play()
PlayingUI.Parent.ea.name.Text = randomTrack.Name
task.wait(5)
PlayingUI.Parent.ea:TweenPosition(UDim2.new(-.233, 0, .723, 0), "In", "Quart", 1, true)
end)
PlayingUI.Parent.ea.OpenHitbox.MouseEnter:Connect(function()
PlayingUI.Parent.ea:TweenPosition(UDim2.new(-0.111, 0, .723, 0), "Out", "Quart", 1, true)
end)
PlayingUI.Parent.ea.OpenHitbox.MouseLeave:Connect(function()
PlayingUI.Parent.ea:TweenPosition(UDim2.new(-.233, 0, .723, 0), "In", "Quart", 1, true)
end)
PlayingUI.Parent.ea.OpenHitbox.MouseButton1Click:Connect(function()
PlayingUI.Parent.ea:TweenPosition(UDim2.new(-.233, 0, .723, 0), "In", "Quart", 1, true)
PlayingUI:TweenPosition(UDim2.new(0.292, 0, 0.238, 0), "In", "Quart", 1, true)
end)
PlayingUI.TextButton.MouseButton1Click:Connect(function()
PlayingUI:TweenPosition(UDim2.new(-0.5, 0, 0.238, 0), "In", "Quart", 1, true)
end)
local function MuteMusic(bool)
PlayingTrack.Volume = bool and 0 or DefaultVol
if PlayingTrack.Volume == 0 then NextVolume = 0 elseif PlayingTrack.Volume == DefaultVol then NextVolume = DefaultVol elseif PlayingTrack.Volume == bool then NextVolume = bool end
end
local function SkipMusic()
if not Player:GetAttribute("PlayMusic") then
return
end
PlayingTrack.TimePosition = PlayingTrack.TimeLength
task.wait(5)
PlayingUI.Parent.ea:TweenPosition(UDim2.new(-.233, 0, .723, 0), "Out", "Quint", 1.5, true) --{-0.233, 0},{0.723, 0}
print ("Skipped!")
task.wait(0.5)
end
--Play()
local db = false
Player:SetAttribute("CurrentTrack","...")
Player:SetAttribute("PlayMusic",false)
MuteBTN.MouseButton1Click:Connect(function()
MuteMusic(PlayingTrack.Volume == DefaultVol)
end)
SkipBTN.MouseButton1Click:Connect(function()
SkipMusic()
task.wait(1)
end)
PlayingUI.Pause.MouseButton1Click:Connect(function()
if PlayingSong.Playing == true then
PlayingSong:Pause()
else
PlayingSong:Resume()
end
end)
Player:GetAttributeChangedSignal("Volume"):Connect(function()
PlayingTrack.Volume = Player:GetAttribute("Volume").Value
MusicVol = Player:GetAttribute("Volume").Value
end)
Thanks for any help!
VIDEO: