Get the Instance(audio in this case) from a table by a number(like: soundEffect[1]).
You want it random, so we use math.random(gets a number between a,b).
So 1 obviously and number of how many is in the table by # .
Results:
Code
local randomSong = soundEffect[math.random(1,#soundEffect)]
if randomSong then
randomSong:Play()
end
If you want a random sound to play, use math.random()
local soundEffect = {
workspace.troll1,
workspace.troll2,
}
function RandomSoundEffect()
return soundEffect[math.random(1, #soundEffect)]
end
local randomSound = RandomSoundEffect()
randomSound:Play()
Basically, RandomSoundEffect will return a sound effect, by picking a number, 1 to #soundEffect
‘#’ basically returns the number of how many items are in a table