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.

local sound = script.Parent
while true do
    local randomAsset = "http://www.roblox.com/asset/?id=" .. math.random(1, 999999999)
    sound.SoundID = randomAsset
    wait(1)
end
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.

local mps = game:GetService("MarketplaceService") -- Get the MarketplaceService
local sound = script.Parent

while true do
    local randomAssetId = math.random(1, 999999999) -- Get the Id first so that we have it seperately from the url
    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
    local musicId = "rbxassetid://" .. randomAssetId -- The id for the audio object

    wait() -- Wait until the asset picking is done, not sure if this is necessary

    local details = mps:GetProductInfo(randomAssetId) or false -- Get the details, or set to false if invalid id
    if details then -- Check if valid object (details exist)
        print("Valid Asset")
        if details.AssetTypeId == Enum.AssetType.Audio then -- Check if the asset is an audio
            print("Audio")
            if details.Creator.Id == 1 then -- Check if the sound is uploaded by roblox (using id for if the ROBLOX account is ever renamed Roblox or something else)
                sound.SoundId = randomAssetUrl -- Finally set the SoundId
                print("Roblox Audio")
            end
        end
    end
    wait()
end

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