Problems with excluding an entity from a 'for' loop

Yes, this is a repost of my previous thread, but just for the sake of me really needing help.

I need some help getting part of a script to work. My issue is that I need a value to be a string rather than userdata in a string.find, but I’ve heard it’s pretty much impossible to convert, so I’m hoping it’s possible to just use the context of what I’m trying to do to properly get the var I would like. Take a look at the example below to know what I mean.

--An example, trying to find whether a prop (in this case, a barrel) exists in an environment or not.
for k, v in pairs( ents.GetAll() ) do
	for i=0,v:GetPhysicsObjectCount() do
	local bone=v:GetPhysicsObjectNum(i)
	if IsValid(bone) then --I NEED to validate it as I need to use it later (you'd know why if this was the original script, but it shouldn't be important).
	  if not string.find( bone, "models/props_c17/oildrum001.mdl" ) then --'string' expected, got userdata
		print("Barrel not found!")
		print("Barrel found!")

In case you missed it,

if IsValid(bone) then

returns a userdata value rather than a string, making the string.find impossible. Please help.

Also, in case it helps, there is an entity using this script, and I would like the script to exclude the entity (assuming it has a barrel as it’s model, as in this example). Maybe I can just use the context of what I want to do?

if v:GetModel() ~= "models/props_c17/oildrum001.mdl" then


You can also use tostring( physobj ), but the model path is sometimes going to be invalid.

--OUTPUT: models/mossman.mdl

--OUTPUT: PhysObject [Mossman.mdl][Entity 645]

Side note: you should make your code indentation more consistent. Here’s a simple example:

This will help massively with development.