|
| 01 Sep 2017 05:44 PM |
Ok so here's what's up. my towers in my tower defense game use a for loop to check for the closest enemy out of all enemies that are on the map and if they are in range, attack them. Most, if not all, my towers play an animation when attacking such as lobbing a bomb in an arc or blasting a plasma ball.
There's a variable early on, set to nil at first, that is changed dynamically by a for loop in the script that uses the :GetChildren() method to find all the enemies on the map.
After this loop finishes, the attack animation plays where the tower attacks the enemy. After the animation, damage calculation is applied to the enemy.
However it appears that when the enemy is killed and :destroy()'ed before the animation finishes, the script breaks, saying that the target is nil or sometimes that their health is not a valid member of the enemy's model.
Since the tower sets a secondary variable as the target, is there a way to check whether or not said target still exists?
The variable is called "CurrentTarget" and I use a FindFirstChild() method to search for it. I know my pathing is correct.
local StillThere = Map.Base:FindFirstChild(CurrentTarget) if StillThere then --finish animation else return end
That was my method for attempting to check on whether or not the target still existed but even if it did the script would not go past that section of the function. |
|
|
| Report Abuse |
|