I have a function that gets called upon when I want to run a notification. Due to yielding in that function, I have wrapped it in a coroutine. The function works perfectly fine.
I have another function that plays a sound. Due to yielding in that function, I have wrapped it in a coroutine. The function works perfectly fine.
I call upon the sound function within the notification function. Once the sound function reaches runService.Heatbeat:Wait(), it simply stops. Nothing happens after that. I removed the Heartbeat:Wait(), and now it gets stuck at Sound:Play(), nothing happens.
I found the sound in the explorer during runtime and it shows that “IsLoaded” is true. But the code never completes.
Something is causing the function to either stop running entirely, or hang forever; specifically when I call upon the Heartbeat:Wait() or sound.Loaded:Wait() or sound:Play().
Even if I don’t run the Sound function under a coroutine (as seen in the Gyazo GIF below), it is still getting stuck there. I’m not sure if it matters, but both of these scripts are in a module script that gets required by multiple local scripts.
Here is a video showing the relevant code, and the output.
https://gyazo.com/aa4ee767b47806fb04ab0a41a1c880b4
Edit: If that isn’t enough for you, I can also record a GIF of the code hanging on sound.IsLoaded:Wait() and sound:Play().
Edit2: When I call this function from other functions that don’t have coroutine.wrap, it works as expected. Why is this happening? Is it intended/known behavior? I have not tested yet, but I wonder if spawn() or delay(0, func) will work?
Edit3: Spawn() isn’t working in my game at all now. Doesn’t matter how I do it;
spawn(function() print'hi' end)
or
local f = function() print'hi' end spawn(f)
Either way, it’s not printing at all. I tried it from the module script and from a local script.
Am I experiencing an engine bug? There is no logic behind this at all as far as I can tell. Threading seems to be nonexistent. (Previously, I had no issues with this).