Hi! This title probably doesn’t fit that well, but I will explain it here!
I am having a slight problem attempting to get the Title from a music ID that is chosen randomly from a table. However, when I tried this I got the following error; https://gyazo.com/3abf2115eb14afcb74fb10cf1f38c05b
This is the only scripting i’ve tried that I thought would work.
local sound = script.Parent.Sound.SoundId == "rbxassetid://"..musicTable[ math.random( #musicTable )]
script.Parent.Sound:Play()
local SoundId = sound -- Sound Id Of The Sound
local Asset = game:GetService("MarketplaceService"):GetProductInfo(SoundId) --[[Get's Product Information Of The Sound--]]
print(Asset.Name) --Print's The Name Of The Audio
script.Parent.title.Text = Asset.Name
wait(1)
local sound = script.Parent.Sound
sound.SoundId = "rbxassetid://"..musicTable[ math.random(1, #musicTable)]
script.Parent.Sound:Play()
local SoundId = sound -- Sound Id Of The Sound
local Asset = game:GetService("MarketplaceService"):GetProductInfo(SoundId) --[[Get's Product Information Of The Sound--]]
print(Asset.Name) --Print's The Name Of The Audio
script.Parent.title.Text = Asset.Name
wait(1)
This may help? Although I just saw one minor error.
What are you trying to do here? You are setting the variable sound to a boolean by comparing script.Parent.SoundId to ““rbxassetid://”…musicTable[ math.random( #musicTable )]”
local sound = script.Parent.Sound.SoundId == "rbxassetid://"..musicTable[ math.random( #musicTable )]
Also, you need to cast the id number to a string
local musicTable = { "18927312", "98179227" } -- example
sound.SoundId = "rbxassetid://"..tostring(musicTable[math.random(1, #musicTable)])
As for your error, You’re calling GetProductInfo on the sound, not the assetid of the sound.
So, kinda got confused by that not gonna lie lmao, here’s what I have now but it’s saying it’s a boolean lmao
local sound = script.Parent.Sound.SoundId == "rbxassetid://"..musicTable[ math.random( #musicTable )]
script.Parent.Sound:Play()
sound.SoundId = "rbxassetid://"..tostring(musicTable[math.random(1, #musicTable)])
local SoundId = sound.SoundId -- Sound Id Of The Sound
local Asset = game:GetService("MarketplaceService"):GetProductInfo(SoundId) --[[Get's Product Information Of The Sound--]]
print(Asset.Name) --Print's The Name Of The Audio
script.Parent.title.Text = Asset.Name
wait(1)
local musicTable = {
'2521392429',
'639750143',
'130762736',
'2862170886',
'225000651',
'130775431',
'141820924',
'587156015',
'1346523498',
'427404831'
}
local sound = script.Parent.Sound
sound.SoundId = "rbxassetid://"..tostring(musicTable[ math.random( #musicTable )])
sound:Play()
local SoundId = sound.SoundId -- Sound Id Of The Sound
local Asset = game:GetService("MarketplaceService"):GetProductInfo(SoundId) --[[Get's Product Information Of The Sound--]]
print(Asset.Name) --Print's The Name Of The Audio
Oh, no need for the tostring call since you are already surrounding your table Id values with ’ '. I was assuming they were stored as numbers not strings. However, that still shouldnt cause an error. What line are you getting the error at?
I need it to cast it from the string ’ ’ to a number only. How would I do that…?
it gives that error on line 44,
local SoundId = sound.SoundId -- Sound Id Of The Sound
local Asset = game:GetService("MarketplaceService"):GetProductInfo(SoundId) --[[Get's Product Information Of The Sound--]]
print(Asset.Name) --Print's The Name Of The Audio
To cast from a string to a number you can call tonumber(string).
Also, you may need to pass in a second parameter to GetProductInfo, which would be Enum.InfoType.Asset. I’m not sure if GetProductInfo defaults to that InfoType, or if it defaults to Enum.InfoType.Product. MarketplaceService | Documentation - Roblox Creator Hub
local musicTable = {
12345657
};
local sound = script.Parent.Sound
local asset_id = musicTable[math.random(1,#musicTable)]
sound.SoundId = "rbxassetid://"..tostring(asset_id)
-- pcall since GetProductInfo can return an error.
local success, product_info = pcall(function()
return game:GetService("MarketplaceService"):GetProductInfo(asset_id, Enum.InfoType.Asset)
end)
local sound_name = success and product_info.Name or "??"