So I'm trying to make a radio gui for my game that's similar to berezaa's radio, where you can switch between music that only you can listen to and change for free, or server music that everyone can hear, but changing it costs you. I have the changing music part almost down, it switches music correctly, but whenever you put in the ID of something that isn't a sound ID, it spams the client log with errors saying that it's not a sound ID. With that said, I wanna know, how do I check if the ID someone puts into the radio is actually a sound ID in the library? I've seen games connect to the catalog and library (catalog heaven, robloxian high school, etc) and I just wanna know how I can connect to the library to tell if the music ID is actually a sound ID. Sorry if I sound redundant, I just really wanna figure out how to do this. Anyways, here's the code I'm using for the local music of my radio:
script.Parent.MusicIdBox.ChooseButton.MouseButton1Click:Connect(function() if script.Parent.MusicIdBox.Text ~= "" then game.Workspace.Music.LocalMusic.SoundId = "http://roblox.com/asset/?id=" .. script.Parent.MusicIdBox.Text game.Workspace.Music.LocalMusic.TimePosition = 0 end end) script.Parent.MusicIdBox.ResetId.MouseButton1Click:Connect(function() script.Parent.MusicIdBox.Text = "474419296" game.Workspace.Music.LocalMusic.SoundId = "http://roblox.com/asset/?id=" .. script.Parent.MusicIdBox.Text game.Workspace.Music.LocalMusic.TimePosition = 0 game.Workspace.Music.LocalMusic.Volume = 0.5 end) script.Parent.PlayButton.MouseButton1Click:Connect(function() game.Workspace.Music.ServerMusic.Volume = 0 game.Workspace.Music.LocalMusic.Volume = 0.5 game.Workspace.Music.LocalMusic:Resume() end)
How about...
You don't.
Make functions, put them inside pcalls, details here: wiki/pcall
UPDATE: Try something like this:
function setMusic() if script.Parent.MusicIdBox.Text ~= "" then game.Workspace.Music.LocalMusic.SoundId = "http://roblox.com/asset/?id=" ..script.Parent.MusicIdBox.Text game.Workspace.Music.LocalMusic.TimePosition = 0 end end script.Parent.MusicIdBox.ChooseButton.MouseButton1Click:Connect(function() pcall(setMusic) end)
Haven't used these in a while.