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

Tried making a radio, printed an error, anyone know the problem?

I have a TextBox that whenever the focus is lost, it takes its text, sets the SoundId of a sound object in the player named "Music" to that text, and plays the music. Here's the script:

local plr = game.Players.LocalPlayer

script.Parent.FocusLost:Connect(function()
	local text = script.Parent.Text -- The parent is the TextBox (the radio) 
	local music = plr.Music
	if text == "" then 
		music.SoundId = ""
		music:Stop()
		script.Parent.Text = "Radio"
	elseif text == "audio1" then 
		music.SoundId = 2862170886 
		music:Play()
		script.Parent.Text = "Radio" 
	elseif text == "audio2" then 
		music.SoundId = 169360242
		music:Play()
		script.Parent.Text = "Radio"
	elseif text == "audio3" then 
		music.SoundId = 235529455 
		music:Play()
		script.Parent.Text = "Radio" 
	else 
		music.SoundId = text
		music:Play()
		script.Parent.Text = "Radio"
	end
end)

"audio1", "audio2", and "audio3" are things i built into the code so if I wanna play a favorite song i can type those instead of remembering the soundid for them.

3 comments

0

"11:03:54.064 - Failed to load sound 169360242: Unable to download sound data" was the error printed

0

I'd like to say that I don't think it will play if it's parented to the Player object, put it inside the character's humanoidrootpart.

0

only the player is supposed to hear the music. Its like a private radio. I would do this for a social radio.

1 answer

✓ Accepted answer

You forgot to add the url link rbxassetid:// infront of the audio ids

local plr = game.Players.LocalPlayer

script.Parent.FocusLost:Connect(function()
    local text = script.Parent.Text -- The parent is the TextBox (the radio) 
    local music = plr.Music
    if text == "" then 
        music.SoundId = ""
        music:Stop()
        script.Parent.Text = "Radio"
    elseif text == "audio1" then 
        music.SoundId = "rbxassetid://2862170886" -- "Old Town Road" 
        music:Play()
        script.Parent.Text = "Radio" 
    elseif text == "audio2" then 
        music.SoundId = "rbxassetid://169360242" -- "Banana Song" 
        music:Play()
        script.Parent.Text = "Radio"
    elseif text == "audio3" then 
        music.SoundId = "rbxassetid://235529455" -- Tomodachi Food Mart Song (fancy) 
        music:Play()
        script.Parent.Text = "Radio" 
    else 
        music.SoundId = text
        music:Play()
        script.Parent.Text = "Radio"
    end
end)

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