Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a possible way to make a music player like this?[Editted]

I was wondering if there was a way you can make a script that will get random audio ids without inputting the ids manually into a script.

Here is what i had in mind if it will work

local MarketplaceService = game:GetService("MarketplaceService")

local Id = math.random(100000000,3000000000)

local productInfo = MarketplaceService:GetProductInfo(Id)

if productInfo.AssetTypeId == 3 then
	-- Play Song
end

5 comments

1

As in from all sound ids in Roblox, or preset random music?

0

All sound ids in Roblox if that is possible.

0

like to get a random one then play it

0

I will edit with something i had in mind but i dont know if it is possible

0

The best way to accomplish this would be if you can grab the IDs from catalog through HTTPService, place them within a table and use math.random to pick a random index

1 answer

✓ Accepted answer

Well, this will iterate through Roblox Ids up to the "max" value

local market = game:GetService("MarketplaceService")
local array = {}

local debounce = true
local max = 3000000000

for i = 0, max do
if debounce == false then return end
debounce = false
	local sound = workspace.Test
	local success, result = pcall(function()
		sound.SoundId = ("rbxassetid://"..i)
	end)
	
	if success and sound.TimeLength > 0 then
		local new = #array + 1
		table.insert(array, new, i)
		print("success")
	else
		warn(result)
	end
	wait()
debounce = true
end
workspace.Test:Destroy()

while true do
	local random = math.random(1, #array)
	for i, v in pairs(array) do
		if v == random then
			workspace.Sound.SoundId = ("rbxassetid://"..v)
			workspace.Sound.SoundId:Play()
			local length = tonumber(workspace.Sound.TimeLength)
			wait(length)
		end
		wait()
	end
end

The above example utilizes two sounds ("Sound" and "Test") in the Workspace There will be errors thrown, but the script will continue running. Due to the sheer amount of assets in ROBLOX this script would still take some time to go through all of the them

Another thing you could try is JSON Decoding on the ROBLOX catalog: https://developer.roblox.com/api-reference/function/HttpService/JSONDecode

The other method you could try is checking the marketplace service asset ids, this will prevent any errors from being thrown but has a cooldown time after 100 checks are reached.

2 comments

0

The only issue is with removed IDs. Removed IDs will yield errors.

0

pcall

This discussion is preserved as it was. New answers, comments, and votes are closed.