CSoundPatch cuts out too early and stops sound

I’ve seen a lot of threads where people are having problems with CSoundPatch, but they’re all from 2009 (so I don’t know if a recent update messed with CSoundPatch) and none of them give me a clear answer to my problem anyways. When I try to play a sound it will just cut out after a few seconds, even if the sound I use (like in this example) is at least thirty seconds long (and supposed to loop). What’s going on here? What I’m I doing wrong, or is CSoundPatch just broken?

The closest I came to finding a solution was with this thread, but I’m not sure exactly what he means. I tried making all the sound related variables I was using global (since someone further down said that was what Azui meant), but it still didn’t work.

This is an example of what I’m trying to do:
[lua]

function cspatchtest( ply )

local outsideSound = Sound( "ambient/ambience/wind_light02_loop.wav" ) 
local outsideSoundStart = CreateSound(  ply,  outsideSound )

outsideSoundStart:Play()

end

concommand.Add( “cspatchtest”, cspatchtest )

[/lua]

Any help would be greatly appreciated.

If I understood it right what he meant:

Your SoundVariable is local so as soon as it is out of the scope it will get deleted, so I guess the sound too. Solution: Make it a global!

Hurr.

I’ll look into this when I get home.

Thanks

[lua]
CSPatch = NULL

local function LocalTest(ply)

local s = Sound("ambient/ambience/wind_light02_loop.wav")
local csp = CreateSound(ply, s)
    
csp:Play()

end
concommand.Add(“CSPTestL”, LocalTest)

local function GlobalTest(ply)

local s = Sound("ambient/ambience/wind_light02_loop.wav") -- All this does is precache and return the string again, no need to make it global.
CSPatch = CreateSound(ply, s)

CSPatch:Play()

end
concommand.Add(“CSPTestG”, GlobalTest)
[/lua]

Local test gave me 1-5 seconds of the sound, then cut off.

Global test however, worked fine. The sound did not stop.

Code was ran on server.

Now that I’ve tried it again, it’s working, maybe I made the sound catch global and not the actual CreateSound. Thank you!

[editline]05:22PM[/editline]

Edit: The reason it was stopping and starting for me was because the place I was putting it was inside a loop.