generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Game Design
Home Search
 

What would you do to check if a target still exists?

Previous Thread :: Next Thread 
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image