So I have this table with a bunch of song id's and I need help getting it to choose a random ID from the table. Help?
Assets = {161475254,89960960,152669449,145869637,157398365,143836328,155319906,142532442,151666823,150444919,156927530,157428830,154684915,142369626,155623794,156963351,143959455,142720946,142402620,142460434,147680226,153474023,150382165} zig = script.Parent.MainWall.SurfaceGui.ScrollingFrame.Sound while true do wait(1) if zig.IsPlaying == false then wait(5) if zig.IsPlaying == false then zig.SoundId = Assets[math.random(1,100)] end end end
The problem is that you're taking a random number between 1 and 100 while there are only 23 items in the Assets table.
Try changing the this line:
zig.SoundId = Assets[math.random(1,100)]
To this:
zig.SoundId = Assets[math.random(1,#Assets)]
That automatically makes it adjust to the size of the table.
Edit:
Sorry, I kind of messed up there. The actual problems are somewhere else. Unfortunately, the IsPlaying property is not actually set to false when the sound has stopped. Instead, you will manually have to enter the duration of each song in seconds, like this:
Assets = { {161475254, 10}, {89960960, 15}, {152669449, 9} }
Note that these are examples. The 10, 15 and 9 are examples of the durations of these sounds. You'll need to look them up for yourself.
The second problem is that you can't just set the SoundId directly to the assetId. Instead you'll have to do this:
zig.SoundId = "rbxassetid://" .. assetId
The third problem is that you don't use zig:Play() anywhere. The sound won't play if you don't tell it to play.
Putting all of these together, the solution is the following:
Songs = { {161475254, 10}, {89960960, 15}, {152669449, 9} -- Add more songs here. First value on each row is the sound's id, the second value is the duration in seconds. } zig = script.Parent.MainWall.SurfaceGui.ScrollingFrame.Sound while true do local songInfo = Songs[math.random(1, #Songs)] -- Choose a random song. zig.SoundId = "rbxassetid://" .. songInfo[1] -- Set the sound id to the song. zig:Play() -- Play the sound. wait(songInfo[2]) -- Wait for the song to end. You must have set the duration. zig:Stop() -- Stop the sound just in case you entered the duration too low. end
I'm pretty sure you've got that part right (changing the ID) it's just you haven't played the sound. I haven't done much anything in aaggess so try doing zig:Play() somewhere there xD