nil values when getting entity player is looking at

I am attempting to make a script that sends entities the player is looking at to the server so the server can do something with that ( doesnt matter now).

This is my client script

function sendPropTable()
	local Client = LocalPlayer()
	local trace = Client:GetEyeTrace()
	if trace.HitNonWorld then


When I run it I get 2 errors:

attempt to call method ‘GetName’ (a nil value)

attempt to index local ‘name’ (a nil value)

Checking if the entity is valid using isValid always returns a true.

What am I doing wrong here?

Entity:GetName is a server function and for the love of god don’t send net messages in a think hook.

if (IsValid(trace.Entity)) then … end

use Nick

trace.Entity is guaranteed to be valid if the “Hit” key is true. “HitNonWorld” can only be true if “Hit” is true.

Thanks! i didnt realise that its a server function.

Also the think hook is only a temporary location for the net.

IsValid returns false for the world, so if the trace hit the world Hit would be true but IsValid(trace.Entity) would be false. The rest of what you said holds though.

Sorry, I didn’t mean valid entity as in IsValid passing, I meant as in a non-NULL entity.