Thoroughly check entities for valid parts

Quick question- what kind of things should I put in the functions below to have more thorough validity checks on the entity in question to avoid script errors?



concommand.Add( 'DamageAllEnts', function()
for _, v in pairs( ents.GetAll() ) do
	if IsValid(v) then -- Some entities are valid but have errors when trying to run the command below
		v:TakeDamage( 5 )
	end
end
end)

concommand.Add( 'ThrowAllEnts', function()
for _, v in pairs( ents.GetAll() ) do
	if ( IsValid(v) && IsValid( v:GetPhysicsObject() ) ) then -- Any solution that doesn't require a mix of clientside and serverside checks?
		v:GetPhysicsObject():ApplyForceCenter( Vector( 0, 0, 2000 ) )
	end
end
end )


It looks good to me.

If you are getting errors, post the damn errors.

Wait, it’s just cause I’m a retard- I was doing



function ENT:OnTakeDamage( dmginfo )
for _, v in pairs( ents.GetAll() ) do
		if IsValid(v) then
			v:TakeDamage( math.floor( 1 ) )
		end
	end
end


Surprised I didn’t notice that…