Boss Attack works with a 1 second cooldown, but not 10

Hi there, I am working on a boss fight that has an attack. I have tested the main mechanic and it seems to work just fine, I left it on with a 10 second cooldown and tested my game. The attack worked once, but after another 10 seconds it just never appeared. I added print(β€œβ€) to my code to see if it registered the second time through, and yes it did but no attack. Then I had the idea of changing the cooldown to 1 seconds instead of 10 seconds, and the attack happened more than 2 times. I will include screenshots below to make what I am saying a bit easier.

Local script firing a remote event to do the attack

image

The wait(1) is the cooldown

The code that the local script is firing.

image

That code works fine.

What it looks in game with 1 second cooldown (after the event has been fired twice)

Then with 10 second cooldown it doesn’t work.

I have spent so long trying to find out the solution to this problem but no solution has popped up in my head, please help me answer my question.

3 Likes

You are breaking from the loop if Count == 20, and incrementing Count inside the loop. However, as Count is declared outside of the function, it is never reset, explaining why it only works one time. Try moving the local Count = 0 line down one line.

4 Likes

Thanks so much! I can’t believe I was so dumb to not realise this :expressionless:

1 Like

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