Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would i make an automatic entity deleter?

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

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

1 comment

0

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.