Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago
Edited 4 years ago
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

Log in to vote
1
Answered by
pwx 1581 Moderation Voter
4 years ago

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()
Ad

Answer this question