Hey, so I am trying to make this code emit a random sound from a part. I also want it to play another sound after the other is done playing. These sounds are children of the part. I wrote this script but it's not playing the sound, I guess it sees 'randomItem' as a number.
local items = script.Parent:GetChildren() for _, v in ipairs(script.Parent:GetChildren()) do if v.ClassName == "Sound" then v:GetChildren(items) local randomItem = math.random(#items) print(#items) randomItem.Playing = true end end
Are there any other methods of doing this better? Please let me know if there are, thanks!
Yeah I think I can help with that
This is wrong If your trying to get a random Item
local randomItem = math.random(#items)
But this is how you do it
local randomItem = items[math.random(1, #items)]
math.random needs 2 values, minimum and maximum numbers. so you can get one item in the Array called "items" by saying "item[number here]" the random number will go there
Please accept if this helped