I'm making a code for my friend. It plays multiple songs though. Could anyone help me with it?
songs = {165065112, 145170576, 177027430, 153219396, 156643822, 180076355, 146682904, 146558717, 165497101, 143649712} while true do local id = math.random(1, #songs) script.Parent.SoundId = "rbxassetid://"..songs[id] script.Parent:Play() wait(10) end
Unfortunately, there is no actual method to determine if a sound has finished playing or not.
One way to try is to use the isPlaying
property.
However, an issue is that if you use :Stop()
or :Pause()
on this before the sound finishes, then it will also make isPlaying
equivalent to false.
The following is one way to do the sound iteration:
songs = {165065112, 145170576, 177027430, 153219396, 156643822, 180076355, 146682904, 146558717, 165497101, 143649712} script.Parent.Looped = false while true do local id = songs[math.random(1, #songs)] script.Parent.SoundId = "rbxassetid://"..tostring(id) script.Parent:Play() repeat wait() until script.Parent.isPlaying == false script.Parent:Stop() wait(10) end
Apparently, you can now use the TimeLength and TimePosition properties of sounds.
So, if this property now works, then you can say:
songs = {165065112, 145170576, 177027430, 153219396, 156643822, 180076355, 146682904, 146558717, 165497101, 143649712} while true do local id = math.random(1, #songs) script.Parent.SoundId = "rbxassetid://"..songs[id] script.Parent:Play() if script.Parent.TimePosition >= script.Parent.TimeLength then script.Parent:Stop() end wait(10) end
Hopefully this works...
To make strings you either need to do this:
songs = {"572647"} --For every single id
or a shorter way
local id = tostring(songs[math.random(1, #songs)])
Now we need to do a bit of tweaking to the script
songs = {165065112, 145170576, 177027430, 153219396, 156643822, 180076355, 146682904, 146558717, 165497101, 143649712} while true do local id = tostring(songs[math.random(1, #songs)]) script.Parent.SoundId = "rbxassetid://"..songs[id] script.Parent:Play() wait(10) end
Hope it helps!