You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want the list to be mixed up and then played, and once that whole list is played then the list is mixed up again and played again. This is so the songs don’t keep playing in the same order.
What is the issue? Include screenshots / videos if possible!
The script isn’t working for some reason and I cant figure out what it is. I know its not working by the fact its not printing “yes” I do know the first part is working though because the first song plays but nothing after that.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Changing the order of the script because I thought that was the issue
local Sounds = {
9046865270,
9047105533,
9046863253,
9047104919,
9046863579,
9047105702,
9046864489,
9046863235,
9047104336,
9047104571,
}
local SoundInstance = Instance.new("Sound", game.SoundService)
while true do
local Table = {}
local SoundsRemaining = #Sounds
repeat
local Sound
repeat
Sound = table.insert(Table, Sounds[math.random(1, #Sounds)])
until table.find(Table, Sounds[Sound]) == nil
table.insert(Table, Sound)
SoundsRemaining = SoundsRemaining - 1
until SoundsRemaining == 0
local currentSound = 0
SoundInstance.SoundId = "rbxassetid://"..Table[1]
currentSound = 1
local Connection = SoundInstance.Ended:Connect(function()
print("yes")
if currentSound >= #Table + 1 then
else
SoundInstance.SoundId = "rbxassetid://"..Table[currentSound + 1]
currentSound = currentSound + 1
SoundInstance:Play()
end
end)
SoundInstance:Play()
print(Connection.Connected)
Connection:Disconnect()
repeat task.wait(1) until currentSound >= #Table + 1
end```
local Sounds = {
9046865270,
9047105533,
9046863253,
9047104919,
9046863579,
9047105702,
9046864489,
9046863235,
9047104336,
9047104571,
}
local SoundInstance = Instance.new("Sound", game.SoundService)
function shuffle(tbl)
for i = #tbl, 2, -1 do
local j = math.random(i)
tbl[i], tbl[j] = tbl[j], tbl[i]
end
return tbl
end
while true do
local shuffledSounds = shuffle(Sounds)
local currentSound = 1
SoundInstance.SoundId = "rbxassetid://"..shuffledSounds[currentSound]
local Connection = SoundInstance.Ended:Connect(function()
currentSound = currentSound + 1
if currentSound > #shuffledSounds then
Connection:Disconnect()
else
SoundInstance.SoundId = "rbxassetid://"..shuffledSounds[currentSound]
SoundInstance:Play()
end
end)
SoundInstance:Play()
repeat task.wait(1) until not Connection.Connected
end
You’re instantly killing the connection before it even has a chance to fire by having Connection:Disconnect() come before the last repeat until loop.
I ended up rewriting the entire thing while I was ironing out some other issues with your code, so here’s a new and improved script LOL. Enjoy.
local Sounds = {
9046865270,
9047105533,
9046863253,
9047104919,
9046863579,
9047105702,
9046864489,
9046863235,
9047104336,
9047104571,
}
local SoundInstance = Instance.new("Sound", game.SoundService)
local LastSoundID = nil
while true do
local ShuffledList = {}
repeat
local Index = math.random(1,#Sounds)
table.insert(ShuffledList,Sounds[Index])
table.remove(Sounds,Index)
until #Sounds == 0
if ShuffledList[1] == LastSoundID then --// Prevent the same sound from being played twice in a row by moving it to be back of the playlist
table.insert(ShuffledList,ShuffledList[1])
table.remove(ShuffledList,1)
end
LastSoundID = ShuffledList[#ShuffledList]
for i,v in pairs(ShuffledList) do
SoundInstance.SoundId = "rbxassetid://"..v
SoundInstance:Play()
task.wait(SoundInstance.TimeLength + 1)
end
Sounds = ShuffledList
end