Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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.

0
"11:03:54.064 - Failed to load sound 169360242: Unable to download sound data" was the error printed User#28017 0 — 4y
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. sweettart13947 105 — 4y
0
only the player is supposed to hear the music. Its like a private radio. I would do this for a social radio. User#28017 0 — 4y

1 answer

Log in to vote
2
Answered by
Prestory 1395 Moderation Voter
4 years ago
Edited 4 years ago

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)
Ad

Answer this question