Hello, I am currently trying to make a radio ui that doesn’t give an error when the player inserts a wrong sound id.
The problem is that I can’t find a way to prevent the error from showing in the output.
I thought that putting the code in a pcall() would stop the error, but it didn’t. After that I thought that I might read some free models for advice but those didn’t help also.
When I test my game in the output it says: Failed to load sound rbxassetid://WrongSoundId: Unable to download sound data (“WrongSoundId” was what I put in the Textbox)
To prevent players entering invalid audio, you have to check that it is audio with MarketplaceService:GetProductInfo(). Here’s the documentation for it.
local market = game:GetService("MarketplaceService")
Play.MouseButton1Click:Connect(function()
if tonumber(MusicId.Text) then
local productInfo = market:GetProductInfo(tonumber(MusicId.Text))
if productInfo.AssetTypeId == 3 then --i think 3 is audio, im not sure though
Sound.SoundId = "rbxassetid://"..MusicId.Text
Sound:Play()
else
--the text was a number, but isnt an id of audio
end
else
--the text isnt a number
end
end)