Entities remove command Help

So I am trying to make a command that when it is called it will remove the entities spawned.

Code:


function removeallspanwed()
local removeall
ents:Remove( "fas2_ammocrate" )
ents:Remove( "npc_shop_zombieevent" )
end

concommand.Add( "removeallzombieeventnpcs", 
removeallspanwed) 

Also I am very new to lua but got the basics of it down.

This should be good:



function removeallspanwed()
	for k, v in pairs( ents.GetAll() ) do // Loop through all of the entites
		if v:GetClass() == "fas2_ammocrate" || v:GetClass() == "npc_shop_zombieevent" then // Check if thier class name is what you need it to be.
			v:Remove() // If its the class's name, remove it.
		end
	end
end

concommand.Add( "removeallzombieeventnpcs", 
removeallspanwed)


That’s one way to do it, another would be using

ents.FindByClass.

Thank You for your help :slight_smile: