Random music script returning error Workspace.Music:9: invalid argument #1 to 'random' (number expected, got table)

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?

Can you post your actual full script? The example you posted shouldn’t be valid, there’s missing statements / mismatched end keyword.

thanks I think thats the problem with my script

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.