So I have a Game Script which is practically the heart of my game, so far most of it has been working but I can't find an efficient way to remove all the enemies that spawn in while the match goes on.
This is how I spawn in enemies (including every variable used, the enemies spawn using wait() )
lightingenemies = game.Lighting.Enemies
enemylist = lightingenemies:GetChildren()
enemy = enemylist[math.random(1, #enemylist)]
fieldenemy = enemy:clone()
fieldenemy.Parent = game.Workspace
fieldenemy:makeJoints()
I've tried these:
childd = game.Workspace:GetChildren()
if childd.Name == enemylist.Name then
childd:Remove()
childd = game.Workspace:GetChildren()
if childd.Name == { "insert" , "thirty" , "different" , "names" , "here"} then --all the names of the units were put above
child:Remove()
i've tried including models in the enemies themselves that makes it so they delete themselves when the value that tells the script if the game is running is false
if gamerun.Value == false then
wait()
script.Parent.Parent:Remove() -- the enemies were put inside another model for naming
-- and so it wouldn't interfere with the enemy's code
-- i've tried putting a while true do and that didn't work either
I'm positive there's a way to do this correctly. Any suggestions would be greatly appreciated, thank you!
Edit: I want to add on to this and apologize for the sloppy coding

1 comment
I assume you have
ends for thoseifstatements. Also, how are you triggering these sections of code? e.g., what event are you binding to for the last one?