Help with Tower Defense wave script

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.

here are some relevant screenshots.
image

bumping its been 2 hours and still an issue

Hard to tell with just this snippet, are you able to provide more context?

Is the WaveEnd bindable the same Instance for both code? Is it somehow firing the WaveEnd event before the Wait connection?

Its impossible that its firing before the wait…
image

this is what the module looks like

also the first wave plays flawlessly but the second just never happens

realised i put the wrong screenshot the edited one is the most recent

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

That’s not what I mean.

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.

Also I don’t know if you saw but I edited the screenshot above because it was the wrong one if you are referring to that one.

Oh I think i see what you mean now ill try that, thanks.

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:

  1. 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.
  2. 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!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.