I'm trying to make an audio playlist that picks a random song and plays it and I thought I had it down but it does absolutely nothing, no errors, nothing.
local audioFolder = game.Workspace.Audios:GetChildren() function selectSong() wait(.2) local pickedSong = math.random(1,#audioFolder) local namePick = tostring(pickedSong) namePick:Play() wait(320) namePick:Pause() end while true do wait(.2) if audioFolder ~= nil then selectSong() wait(2) else print("Audio folder does not exist") end end
Please help, thanks!
You forgot to wrap the table "audioFolder" with these little brackets, "[]". Also, adding a tostring is unnecessary since you want the audio itself, so use these lines instead
local pickedSong = audioFolder[math.random(#audioFolder)] local namePick = pickedSong
Instead of the sound objects themselves, you could do this.
local soundIds = {28727449, 2928484, 19395, 29284, 38272} -- random numbers -- put the proper id's in the table local soundId = soundIds[math.random(1, #soundIds)] local sound = Instance.new("Sound",game.Workspace) sound.SoundId = "rbxassetid://"..soundId
pickedSong in your script will only be a number not a song. So you need to access the actual song like so:
local song = audioFolder[pickedSong] -- remember picked song is a number -- this is just an example
then you should be good to go.