Hello people.
I am currently making a game with a music system, but I recently edited it to try and make it select a random song id from my table using math.random(), but it won't work.
Can someone please help me solve this problem?
Thanks! Here's the script:
local sounds = {
247020473, -- Tinie Tempah - Pass Out
404211423, -- The Black Eyed Peas - I Gotta Feeling (Instrumental)
1062968079, -- Nicki Minaj - Starships
144567977, -- Olly Murs - Troublemaker (Ft. Flo Rida)
152102303, -- Owl City - Good Time (Ft. Carly Rae Jepsen)
}
local music = script.Parent
while true do
wait(5)
music.SoundId = "rbxassetid://"..math.random(1, #sounds)
music:play()
music.Ended:wait(1)
music.SoundId = "rbxassetid://"..math.random(1, #sounds)
music:play()
music.Ended:wait(1)
music.SoundId = "rbxassetid://"..math.random(1, #sounds)
music:play()
music.Ended:wait(1)
music.SoundId = "rbxassetid://"..math.random(1, #sounds)
music:play()
music.Ended:wait(1)
music.SoundId = "rbxassetid://"..math.random(1, #sounds)
music:play()
music.Ended:wait(1)
end

4 comments
Thank you very much Leamir! Is there any way to repeat the function forever?
After line 17 in Leamir's code, just put this: NewSound()
Thank you zyrun!
Thanks, zyrun!