So when I click the next button on it it will play the first time but when I click it again it will not play the next song.
Error:
Players.FuriaI.PlayerGui.mp3player.BackGround.Main:69: bad argument #2 to 'random' (interval is empty) 09:13:23.975 - Stack Begin 09:13:23.976 - Script 'Players.FuriaI.PlayerGui.mp3player.BackGround.Main', Line 69 - global NextSong 09:13:23.977 - Script 'Players.FuriaI.PlayerGui.mp3player.BackGround.Main', Line 81
Script:
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local Character = Player.Character
local Bg = script.Parent
local Bar = Bg.Bar
local PlayPause = Bg.PlayPause
local Prev = Bg.Prev
local Next = Bg.Next
local SongImg = Bg.ImageLabel
local Song = Bg.Song
local Time = Bg.Time
local SongIsPlaying = false
local SoundIds = {
897623161,844906598,
}
local ChosenSong = {}
local PrevSongg = {}
table.sort(SoundIds)
function GetIndex(tabl)
for i,v in pairs(tabl) do
return v
end
end
function CheckIfPlaying()
if SongIsPlaying == true then
return true
elseif SongIsPlaying == false then
return false
end
end
function PlaySong()
local Sound = Instance.new("Sound")
Sound.Name = "Music"
if Character.Torso:FindFirstChild("Music") then
Character.Torso.Music:Destroy()
end
Sound.Parent = Character.Torso
for i,v in pairs(ChosenSong) do
Sound.SoundId = "rbxassetid://"..v
end
Sound.Looped = true
Sound.Volume = 1
Sound.TimePosition = 0
Sound:Play()
end
function NextSong()
if CheckIfPlaying() then
for i,v in pairs(ChosenSong) do
table.insert(SoundIds,v)
for g,h in pairs(PrevSong) do
table.remove(PrevSong,h)
table.insert(PrevSong,v)
end
table.remove(ChosenSong,v)
end
local index = math.random(1, #SoundIds);
table.insert(ChosenSong, SoundIds[index]);
table.remove(SoundIds, index);
PlaySong()
elseif not CheckIfPlaying() then
local index = math.random(1, #SoundIds);
table.insert(ChosenSong, SoundIds[index]);
table.remove(SoundIds, index);
PlaySong()
end
end
function PrevSong()
-- Will Work On This
end
Next.MouseButton1Click:Connect(function()
NextSong()
end)
Prev.MouseButton1Click:Connect(function()
PrevSong()
end)
PlayPause.MouseButton1Click:Connect(function()
if table.getn(ChosenSong) > 0 then
PlaySong()
else
local index = math.random(1, #SoundIds);
table.insert(ChosenSong, SoundIds[index]);
table.remove(SoundIds, index);
end
end)

2 comments
Thank you man!
You're welcome! :)