Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to do an audio randomizer? (script and error if needed inside the question) [ANSWERED!]

local list = script.Parent.songlist:GetChildren()

while wait(0) do
	local randomaudio = math.random(1, #list)
	randomaudio:Play()
	wait(randomaudio.TimeLenght)
end

Workspace.Radio.sound.RANDOM:5: attempt to index local 'randomaudio' (a number value)

If you read this, you are epic.

Please fix my little problem, thanks!

1 answer

✓ Accepted answer

You have the right idea, you almost have it!

You've given the numbers for math.random but have not defined where to get the audios from.

local tableOfSounds = {sound1, sound2, sound3}

local randomSound = tableOfSounds[math.random(1, #tableOfSounds)]
-- What we are doing here is taking out a sound from the table, using math.random to pick from that table.
randomSound:Play()

This discussion is preserved as it was. New answers, comments, and votes are closed.