Failed to load sound rbxassetid://: HTTP 404

Hello I am working on making a radio gear.
I have a gui in StarterGui that is shown when the player clicks while the radio is equipped. The gui has a textbox to put the sound id into and a play button. However when I click play I get this error “Failed to load sound rbxassetid://: HTTP 404” twice.
Also for some reason repeated button presses don’t produce the error again.

Local script in the gui:

local SoundId = script.Parent.Parent.TextBox.Text
local Radio = game.Players.LocalPlayer.Backpack.Radio

script.Parent.MouseButton1Click:Connect(function()
	Radio.PlaySong:FireServer(SoundId)
end)

Server script in the radio gear:

local Sound = script.Parent.Radio.Sound

script.Parent.PlaySong.OnServerEvent:Connect(function(player, SoundId)
	Sound.SoundId = 'rbxassetid://'..SoundId
	Sound:Play()
end)

The status code 404 means “not found.” Also, you’re concatenating tostring(Sound), which is a string representation of the variable referencing the sound instance.
You’re supposed to be doing "rbxassetid://" .. SoundId, since that’s the parameter in your OnServerEvent connection

1 Like

This is an old version of the server script that still gives the same error:

local Sound = script.Parent.Radio.Sound

script.Parent.PlaySong.OnServerEvent:Connect(function(player, SoundId)
Sound.SoundId = ‘rbxassetid://’..SoundId
Sound:Play()
end)

Also I know that 404 means not found but idk why it can’t find the id

Well, that’s because your SoundId variable isn’t being set when the player presses the “Play” button…

local SoundId = script.Parent.Parent.TextBox.Text -- this doesn't get updated!
local Radio = game.Players.LocalPlayer.Backpack.Radio

script.Parent.MouseButton1Click:Connect(function()
	-- it's just using the Text that the TextBox originally had;
	-- could be "", could be "Text"
	Radio.PlaySong:FireServer(SoundId)
end)

Instead, you need to provide the current text within the box:

local Radio = game.Players.LocalPlayer.Backpack.Radio

script.Parent.MouseButton1Click:Connect(function()
	-- You should be grabbing the property HERE.
	local SoundId = script.Parent.Parent.TextBox.Text
	Radio.PlaySong:FireServer(SoundId)
end)

Though, you should be sanitizing the player’s input nonetheless. Especially on the server:

PlaySong.OnServerEvent:Connect(function(Player, SoundId)
	-- Note that you have NO CONTROL over what the player can send here;
	-- it could be a string, buffer, number, etc... so,
	-- sanitize the input!
	if typeof(SoundId) ~= "string" then
		-- Simply don't change the sound ID if it's not a string.
		-- That means the player sent something they shouldn't have
		return
	end

	local SanitizedId = tonumber(SoundId) -- Convert the string to a number
	-- Then, check if it's nil. tonumber will always return nil if there's no valid number
	if SanitizedId == nil then
		return
	end
	-- NOW, you can set the SoundId, knowing it's a number
	-- I use string interpolation here since it's much nicer on the eyes
	Sound.SoundId = `rbxassetid://{ SanitizedId }`
	Sound:Play()
end)
1 Like

Why should I sanitize player input, it works regardless. Is sanitizing for security?

Yes. Exploiters are able to send anything through remotes; if you haven’t heard of the term “never trust the client,” I would suggest looking into what sanity checks are.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.