CreateSound cuts out randomly

So I tried this

	ply.tauntPatch = CreateSound( ply, taunt )
	ply.tauntPatch:SetSoundLevel( 100 )
	ply.tauntPatch:PlayEx(1, pitch)

on a clientside file
and it works good, however it glitches out occasionally it’s like the sound gets gc’d or something because it just stops playing sometimes. Is there any way to make the sound play normally every time?

Never used those functions before but maybe giving sound.PlayFile a try will inadvertently fix the issue?

I appreciate the recommendation, however I don’t think I can parent that to an entity.

I would really just like to figure out why my csoundpatches go quiet

The sounds cutting out is due to you using SetSoundLevel with a huge value. According to the dev wiki the higest used value in hl2 is 3.9. I’d tinker around with it.

I can’t seem to find any example code that actually uses SetSoundLevel. Setting it to 1-3.9 doesn’t work at all. Why are you playing with the soundlevel anyway? Do you want the sound to play farther away?

According to the old wiki the value actually should be between 60 and 160. I was mis-reading. SetSoundLevel( 90 ) seems to work fine for me.

Yeah I need the sound to be heard from all over the map, that is why I am altering soundlevel.

[editline]21st August 2014[/editline]

also I tried changing the sound level and it still cuts out as usual

You can set the SoundLevel to 0 and it will play globally. Also if the sound is still cutting out at 90 have you tried a different file?

Even at soundlevel 0 it still happens, I tried it on a server sided file and the issue persists :confused:

also I tried running __gc on the sound patch right after playing it and it is silenced ( as expected ) so I am really starting to believe this is a gc issue.

That’s really weird. Maybe the map? Do you see something like current_channels == MAX_CHANNELS or similar in console? If so then your playing too many sounds at once. Otherwise I’m kinda just pulling guesses out of the air.

It was most definitely a GC issue, I removed the GC function and it works PERFECT.

local s = Sound(taunt)
	ply.tauntPatch = CreateSound( ply, s )
	if( ply.tauntPatch.__gc ) then
		local smeta = getmetatable(ply.tauntPatch)
		smeta.__gc = function()
			print( "No Thanks" )

	ply.tauntPatch:SetSoundLevel( 00 )
	ply.tauntPatch:PlayEx(1, pitch)

anyone know what type of ent this creates*? I need to create my own gc function so that nothing bad happens ( will it? )