i could have tested this actually, leaving it in there breaks it, so ima look what the issue is and ill get back
That should be getting handled here.
what part sets the target to nil if its not in range?
If no target is found that is in range, it will never resolve. It will be thrown into the rejection handler, and handled by :catch
.
so how do i do the repeat in the seperate module script, as in it should repeat until what
From the way it seems you have it setup, it should not be repeating at all. It should simply be Running Humanoid::TakeDamage
and then stopping. If you have it repeat it will constantly hit the target no matter what until the target is dead. This disregards distance and tower cooldowns.
yeah so original idea was that it keeps dealing continous damage until the target is either dead or out range, and it should do this without returning to the main script because then it would play the animation
That is flawed as it would allow the tower to start hitting multiple targets, and when the target leaves the range of the tower it would still inflict damage. Essentially a tower only needs to hit every target once and they will all just die over time. The only time you should be repeating damages like this is if you have a poision tower or a sort of debuff tower that applies a certain debuff for X amount of time.
ok ima take a step back
so i could just make its cooldown very quick to do this so that then it will deal damage contionusly, but that makes it return to the main script which means the animation plays
basically i want damage to repeat but not animation
TLDC: The way you’re currently handling this would mean that if the target came in range of the tower, it would start taking damage. After it left the range of the tower, it would continue taking damage until it died.
Your issue of infinite range towers seems to not necessarily be true, the target has to come in range of the tower at least once, but then afterwards it will be targeted until it dies, no matter how far away it is.
i mean actually i could probably just check in the main script if its this tower and not play the animation if it is this tower, and then i could just do the animation in the seperate module script
only reason i didnt want it to go back to the module script is bc i didnt want it play the animation
still thank you very much for making the targetting better than the if statements
hi, i just realised i was stupid, there is no way to only play the animation the first attack and not for the rest. it doesn’t make much sense but all that matters is that it doesnt work
basically animation plays, target keeps taking damage until he is dead
if you have any ideas let me know
Remove the repeat loop. Module.Attack should only be called Humanoid::TakeDamage once.
sure we don’t need to use the repeat loop but the target should take damage until he’s dead
That is for your tower to handle, not a repeat loop. After the tower’s cooldown, it will call it’s own method again causing the mob to take more damage. That is the point of your tower cooldown, and that is the point of your tower having a set range.
right but if it calls the attacking function again then the animation will also play again
Every time it attacks, it should have to play the attacking animation. And anyways, it would be better than what the code is currently doing. Essentially you have a stacking infinite damage Attack function, as currently it will constantly repeat the Humanoid::TakeDamage
, and Module.Attack
will also be constantly repeated because the tower will still hit already hit enemies.
think of it as something like a poison dart, tower shoots it into the target, and that will constantly damage the target, but you dont want to play the tower shooting animation everytime the enemy takes damage, because the poison dart is already in him
Unless if all of your towers do infinite-lasting stacking poison damage, which none of them should, you should not be making this your Module.Attack
that will handle all attacks. Instead that should be handled explicitly by the tower.Attack
itself.