Entity:GetClass() returning nil

Hi, im making a custom function for E2 and in order to narrow down what the function finds i have included


 if ent:GetClass() == "gmod_wire_expression2" then 

however this returns the error (the line of code above is on line 16):

sv: Expression 2 (generic): entities/gmod_wire_expression2/core/custom/emp.lua:16: attempt to call method ‘GetClass’ (a nil value)

I have already performed checks to see if the entity is valid so i know thats not the problem, if anyone can help me solve this problem it will be greatly apreciated!

This error message means that in this case ent is not a valid entity since it doesn’t have the GetClass method. You might want to use ValidEntity(ent) first.

Hey, i added that and it still returned an error so i added:


if(ValidEntity(ent)) then 
self.player:ChatPrint("yes
") 
end 

After adding that peice of code, it returns the error:

sv: Expression 2 (generic): lua\includes\util.lua:168: attempt to call method ‘IsValid’ (a nil value)

Show us more code.