Hey guys! Long time no see, well im here, but this time, with my hands empty, my purpose is that you tell me how would i make a code that automatically deletes something specific when it exceedes, this is, to prevent lag of course, i have a zombie spawner at my world, it spawns zombies infinitely every 20 seconds but eventually the zombies will get to big numbers. but i don't want to tamper with the spawner directly, so i just want to make a script that deletes some specific object when it exceeds a quantity limit, i don't want anyone to do any code for me, unless it's necessary to explain, it would be good if you just explained how to do this to me in words, or in small inline codes. Thanks
✓ ANSWER ACCEPTED
How would i make an automatic entity deleter?
1 answer
✓ Accepted answer
here's my initial thought...
while wait(1) do --loops every one second
if #zombies >= maxCount then --checks if the no. of zombies is greater than the maxCount
zombies[math.random(1,#zombies)]:Destroy() --deletes a random zombie
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thank you! but in this case, what should i replace "#zombies" and "zombies" with, should i replace that with game.Workspace.ZombieSpawner.Zombie for example?