Need Help with a script to remove a weapon from inventory if the weapon has no ammo.

	for k,v in pairs( ply:GetWeapons() ) do
		if v:GetAmmoCount() == 0 then
			ply:StripWeapon( v )

I am using that currently but it doesn’t work. I was wandering if anyone can tell me why that doesn’t work. Any help is appreciated.

Well when do you run the code?


PlayerLoadout only gets run when the player’s meant to get weapons, which seems to be only at the start of the round - try using something like

GM/EntityFireBullets so it gets called whenever bullets are fired, which is probably more suitable

or in a timer/think

Well, you could do that, but I think it’d be better to only call it when it’s actually needed (as in when bullets are fired)

I think there is a problem with the rest of the code too. I’m not sure though

Pretty sure StripWeapon’s argument is a string, not an entity.
So you’ll have to do v:GetClass()