Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I get a random sound by Roblox?

Asked by 4 years ago

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.

1local sound = script.Parent
2while true do
3    local randomAsset = "http://www.roblox.com/asset/?id=" .. math.random(1, 999999999)
4    sound.SoundID = randomAsset
5    wait(1)
6end
0
You cannot unless you get it manually. IEntity_303I 80 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

This takes forever, but theoretically works. Hopefully it can be made faster.

01local mps = game:GetService("MarketplaceService") -- Get the MarketplaceService
02local sound = script.Parent
03 
04while 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")
View all 23 lines...

But that takes forever. I'd recommend putting some of your favorite APM tracks into a folder and picking random tracks from that folder.

Ad

Answer this question