attempt to call method 'GetEyeTrace' (a nil value)

So im getting this error on my server and its flooding my console. Im wondering how i could fix it here is my code:


function GM.Property:PaintDoorText()
	local door = LocalPlayer():GetEyeTrace().Entity
	if not IsValid( door ) or not self.m_tblDoorCache[door:EntIndex()] then return end
	if LocalPlayer():GetPos():DistToSqr( door:GetPos() ) > 16384 then return end

	local pos, ang, posBack, angBack, width, hitWorld = self:CalculateDoorPositioning( door )
	render.SuppressEngineLighting( true )
	cam.Start3D2D( pos, ang, 0.02 )
		self:PaintDoorCard( pos, door, door:GetModel() )
	cam.End3D2D()
	
	cam.Start3D2D( posBack, angBack, 0.02 )
		self:PaintDoorCard( pos, door, door:GetModel(), true )
	cam.End3D2D()
	render.SuppressEngineLighting( false )
end 

Make sure LocalPlayer is valid before running the code.

Ya see i am doctor dumb ass and don’t even know how to do that :stuck_out_tongue:

if (LocalPlayer() == NULL) then return end

Like so?


function GM.Property:PaintDoorText()
        if (LocalPlayer() == NULL) then return end
	local door = LocalPlayer():GetEyeTrace().Entity
	if not IsValid( door ) or not self.m_tblDoorCache[door:EntIndex()] then return end
	if LocalPlayer():GetPos():DistToSqr( door:GetPos() ) > 16384 then return end

	local pos, ang, posBack, angBack, width, hitWorld = self:CalculateDoorPositioning( door )
	render.SuppressEngineLighting( true )
	cam.Start3D2D( pos, ang, 0.02 )
		self:PaintDoorCard( pos, door, door:GetModel() )
	cam.End3D2D()
	
	cam.Start3D2D( posBack, angBack, 0.02 )
		self:PaintDoorCard( pos, door, door:GetModel(), true )
	cam.End3D2D()
	render.SuppressEngineLighting( false )
end 

Yes

That still does not fix the error May i add you on steam?

I rather not; it disadvantages people who have a similar issue from finding the source of the issue. Try this:


function GM.Property:PaintDoorText()
        if (not LocalPlayer().GetEyeTrace) then return end
	local door = LocalPlayer():GetEyeTrace().Entity
	if not IsValid( door ) or not self.m_tblDoorCache[door:EntIndex()] then return end
	if LocalPlayer():GetPos():DistToSqr( door:GetPos() ) > 16384 then return end

	local pos, ang, posBack, angBack, width, hitWorld = self:CalculateDoorPositioning( door )
	render.SuppressEngineLighting( true )
	cam.Start3D2D( pos, ang, 0.02 )
		self:PaintDoorCard( pos, door, door:GetModel() )
	cam.End3D2D()
	
	cam.Start3D2D( posBack, angBack, 0.02 )
		self:PaintDoorCard( pos, door, door:GetModel(), true )
	cam.End3D2D()
	render.SuppressEngineLighting( false )
end

Oh thank you very much that fixed it.