Code:
local Player = game.Players.LocalPlayer
local availableMusic = game.ReplicatedStorage:WaitForChild("Music"):GetChildren()
local PlayingTrack
local PlayingUI = Player.PlayerGui:WaitForChild("NowPlaying").Frame
local SkipBTN = PlayingUI.skip
local MuteBTN = PlayingUI.Mute
local DefaultVol = 5
local Count = 0
local DB = false
local function PlayNexTrack()
if not Player:GetAttribute("PlayMusic") then return end
local randomTrack = availableMusic[math.random(1,#availableMusic)]
Player:SetAttribute("CurrentTrack",randomTrack.Name)
PlayingTrack = randomTrack
randomTrack:Play()
print ("Playing", randomTrack.Name)
randomTrack.Ended:Connect(PlayNexTrack)
end
local function CheckForBug()
for i = 1, #availableMusic do
--issue 1
--Kinda confused on what to do here. I want it to check if the song is playing.
--If it is, add 1 to count. If count is 2, stop the one that isn't playing.
end
end
local function ToggleMusic()
if Player:GetAttribute("PlayMusic") then
Player:SetAttribute("PlayMusic",false)
else
Player:SetAttribute("PlayMusic",true)
end
end
local function MuteMusic(bool)
PlayingTrack.Volume = bool and 0 or DefaultVol
print (PlayingTrack.Volume)
end
local function SkipMusic()
if not Player:GetAttribute("PlayMusic") then return end
PlayingTrack.TimePosition = PlayingTrack.TimeLength
print ("Skipped!")
wait(0.5)
end
--PlayNexTrack()
Player:GetAttributeChangedSignal("PlayMusic"):Connect(function()
if Player:GetAttribute("PlayMusic") then
PlayNexTrack()
else
PlayingTrack.Playing = false
end
end)
Player:GetAttributeChangedSignal("CurrentTrack"):Connect(function()
PlayingUI.Playing.Text = Player:GetAttribute("CurrentTrack")
end)
Player:SetAttribute("CurrentTrack","...")
Player:SetAttribute("PlayMusic",true)
MuteBTN.MouseButton1Click:Connect(function()
MuteMusic(PlayingTrack.Volume == DefaultVol)
end)
SkipBTN.MouseButton1Click:Connect(function()
SkipMusic()
wait(1)
end)
Player.MusicPlaying.Value.Changed:Connect(function() --issue 2, i dont want it to play if MusicPlaying is false, but if it's true then play
--it shouldn't set Playing to false after a song is done playing..
if DB == false then
DB = true
end
end)
Hi!
Issue 1: Music randomly plays 2 at the same time
Video proof:
I don’t know what’s causing this.
Issue 2: How do I make it stop with a value in Player?
Very simple, what the name says. I need the music to pause using UI sometimes.
Thanks for any help!