Music = { ["Bryson Tiller - Been That Way"] = { Artist = "Bryson Tiller", ItemId = "http://www.roblox.com/asset/?id = 313095574", Length = 0 }, ["Drake - God's Plan"] = { Artist = "Drake", ItemId = "http://www.roblox.com/asset/?id = 1375384985", Length = 0 }, ["Bryson Tiller - You Got It"] = { Artist = "Brsyon Tiller", ItemId = "http://www.roblox.com/asset/?id = 977685900", Length = 0 }, }
So I wanna get a random Item Id in this table. How would I get a random ItemId? Basically, I want it to pull a random Item Id. So then I can still pull the title and the artist of the song. How could this be done? I've been stuck at figuring this out for several minutes.....
See below for how I would do it.
Music = { { ['song'] = 'Bryson Tiller - Been That Way', ['artist'] = 'Bryson Tille', ['itemId'] = 'http://www.roblox.com/asset/?id=313095574', ['length'] = 0 }, { ['song'] = 'Drake - God\'s Plan', ['artist'] = 'Drake', ['itemId'] = 'http://www.roblox.com/asset/?id=1375384985', ['length'] = 0 }, { ['song'] = 'Bryson Tiller - You Got It', ['artist'] = 'Brsyon Tiller', ['itemId'] = 'http://www.roblox.com/asset/?id=977685900', ['length'] = 0 } } local getRandomSongId = function() return Music[math.random(1, #Music)]['itemId'] end getRandomSongId()
Personally I would stick to using arrays for the higher levels in the hierarchy and then use a dictionary at the last level.
Hope this helps, if not I'm sure there is away to do it with your current set up.
local pick = Music[math.random(1,#Music)]