I want to create a random song picker, however I keep running into the following error
Workspace.Music:9: invalid argument #1 to 'random' (number expected, got table)
This is my code:
local music = script:GetDescendants()
print(music)
local random = music[math.random(#music)]
local previous = '' --get the song that was played before
function music()
while true do
if random == previous then
wait(0.1)
random = music[math.random(#music)]
music()
end
print('Now Playing:', random.Name)
random:Play()
wait(math.floor(random.TimeLength * 1))
previous = random
music()
end
end
music()
I have tried other functions like script:GetChildren()
and the one used now script:GetDescendants()
none of them work though.
I looked everywhere on the dev forum, but no solutions are working for me.
Can anyone help?