I want to get a random sound from Roblox, to make some sort of radio. Like play a random sound from the hundreds of audio that ROBLOX has uploaded. Putting in all of the APM music that Roblox has uploaded in a table would be impossible, and I'm sure there's a way to automate this.
1 | local sound = script.Parent |
2 | while true do |
3 | local randomAsset = "http://www.roblox.com/asset/?id=" .. math.random( 1 , 999999999 ) |
4 | sound.SoundID = randomAsset |
5 | wait( 1 ) |
6 | end |
This takes forever, but theoretically works. Hopefully it can be made faster.
01 | local mps = game:GetService( "MarketplaceService" ) -- Get the MarketplaceService |
02 | local sound = script.Parent |
03 |
04 | while true do |
05 | local randomAssetId = math.random( 1 , 999999999 ) -- Get the Id first so that we have it seperately from the url |
06 | local randomAssetUrl = "http://www.roblox.com/asset/?id=" .. randomAssetId -- Does the normal thing, but with our variable instead of making up the id then and there |
07 | local musicId = "rbxassetid://" .. randomAssetId -- The id for the audio object |
08 |
09 | wait() -- Wait until the asset picking is done, not sure if this is necessary |
10 |
11 | local details = mps:GetProductInfo(randomAssetId) or false -- Get the details, or set to false if invalid id |
12 | if details then -- Check if valid object (details exist) |
13 | print ( "Valid Asset" ) |
14 | if details.AssetTypeId = = Enum.AssetType.Audio then -- Check if the asset is an audio |
15 | print ( "Audio" ) |
But that takes forever. I'd recommend putting some of your favorite APM tracks into a folder and picking random tracks from that folder.