Hello Devforum. I have an issue with my td wave module that I done really understand. The idea is that the module will spawn a wave of enemies until the set parameter of enemies is fulfilled. I actually had this working perfectly but I had to rollback my game because of another issue and now it just doesn’t work as it did before. I’ve tried moving the code around in all sorts of ways, please help this is a last resort. (By the way I’m using bindableevents)
I know the module is firing the event from debugging, its as if the main script doesn’t see it.
Well in this case I think it is. The StartWave function never ends because of your while true do loop, meaning the code after running StartWave will get blocked. Consider running the while true do in a separate thread.
I don’t believe that’s true. The print after the bindable event does run at the correct time, also I had this working great before and I didn’t change anything about the loop. Not to mention the coroutine which is essentially creating a new thread already
All your code inside your while true do loop will run just fine, I’m talking about the loop itself yielding the current thread. You can test this by adding a print just right after you call StartWave and see that it will not print.
That was the issue thank you! all I had to do was not have a while true loop. I added the while true loop while debugging my pause system (its not needed at all). I appreciate your help. Here is the fixed code if you care
No problem, but I would like to clarify 2 thhings to give you the proper answers:
The while loop is still technically blocking the thread, but you now have a loop condition that will properly break the loop compared to your old code.
With this setup, you technically do not need the BindableEvent anymore, as your pattern will yield the current code anyways:
local function whileFunction(): ()
while someCondition do
print("second")
end
print("third")
end
print("first")
whileFunction()
print("fourth")
-- first
-- second (until condition isn't met)
-- third
-- fourth
well… I actually kind of figured that it wasn’t needed after I posted that screenshot. But what actually happened is it for whatever reason didn’t yield and just played the next wave over and over and it never had any sort of cooldown. I can confirm that the bindable event is for sure needed, if you want to figure out why that is go ahead but I’m fully fine with this solution for now. Thanks!