"Error: The resource was not found (-3)" when calling resource.set_sound

Hi, I’m currently trying to load and then play a sound file like so:

local sfx, error = sys.load_resource(file_path)
	if sfx == nil then
		print(error)
		return
	else
		print("sfx loaded successfully")
	end
	resource.set_sound("/game#sound", sfx)
	sound.play("/game#sound")

When I call this code I’m seeing the “sfx loaded successfully” message trigger, but on the resource.set_sound line I’m getting the following error:

“The resource was not found (-3): 16788874045146231225, /game#sound”

I’ve checked in my project and “/game#sound” is the correct URL for the sound component, and printing the file_path variable shows that the value is what I expect it to be .

resource.set_sound is not used on a sound component, but on the resource of a sound component. So you need:

resource.set_sound(go.get("/game#sound", "sound"), sfx)
3 Likes

Ah thank you, that’s solved it :+1: