So recently I've decided to make a new showcase and wanted to try my hand at making an ambient music player, one that is stuck to a Part and the farther away you go, the quieter it becomes, which is simple enough in it's own right as it's built in. My problem is with actually Scripting a working playlist that goes through a list of 4 songs and starts back over at the beginning. Every single time I've tried a new script it'll just loop the first song, or play all four at the same time without fail. I'm pretty bad when it comes to Lua so any help is appreciated This is the script I tried using:
local sound1 = 131072261 local sound2 = 130872377 local music = script.Parent
while true do wait() music.SoundId = "rbxassetid://"..sound1 music:Play() music.Ended: wait() music.SoundId = "rbxassetid://"..sound2 music:Play() music.SoundId = "rbxassetid://"..sound3 music:Play() music.Ended: wait() music.SoundId = "rbxassetid://"..sound4 music:Play() music.Ended: wait() end
I've actually done this before, hopefully I can show you something cool and maybe you'll learn something from it :D !
--Server script local soundObject = Instance.new("Sound") --im just creating this so you can easily copy-paste and mess around soundObject.Volume = 1 soundObject.Parent = workspace --creating a table of songs, i believe this is an array. local songTable = { [1] = "rbxassetid://1771529564"; [2] = "rbxassetid://1836914205"; [3] = "rbxassetid://1572323159"; [4] = "rbxassetid://2087798404"; } local function repeatTable() for i, v in pairs (songTable) do --loop through the array soundObject.SoundId = v --value of iteration soundObject:Play() --play sound soundObject.Ended:Wait() --wait till the song is over to continue end end while true do repeatTable() wait() end
Hope this helped m8.
P.S Listen to the dope beats I put in the table