Need help with ToScreen() method

I don’t know why, but it always says it has a nil value, this is what I did:


I don’t know where is the error D:

Show the actual error you get along with more code than a single line.

function SWEP:PrimaryAttack()
    if ( !self:CanPrimaryAttack() ) then return end
    self:ShootBullet( 1, 1, 0.015 )
    self:TakePrimaryAmmo( 1 )
    self.Owner:ViewPunch( Angle( -1, 0, 0 ) )
    local data = {}
        data.start = self.Owner:GetShootPos()
        data.endpos = data.start + self.Owner:GetAimVector()*10000
        data.filter = self.Owner
        local trace = util.TraceLine(data)
    if (SERVER and trace.Hit) then
        local entity = trace.Entity
            if (IsValid(entity) and entity:IsPlayer()) then
                local vec = (trace.HitPos - trace.StartPos):GetNormal()
                local contador = entity:GetNetworkedVar("contador")
                vec.z = math.abs(vec.z) + 0.175
                if entity:GetNetworkedInt("anonymous") == 0 then
					entity:SetVelocity(vec * contador)
				elseif entity:GetNetworkedInt("anonymous") == 1 then
					entity:SetVelocity(vec * contador/10)
   	self.Weapon:SetNextPrimaryFire(CurTime() + 0.155 ) 
   	local position = self.Owner:GetPos()
   	local position2D = position:ToScreen()

The error happens here

local position2D = position:ToScreen()

Edit: The error says: attempt to call method “ToScreen” <a nil value>

Check for clientside cos ToScreen is clientside function.
if CLIENT then
local position = self.Owner:GetPos()
local position2d = position:ToScreen()

I see, It works(but I don’t see nothing on the print),but my real problem is this code right here:
(This is on a clientside file)

function GM:Think()
	if LocalPlayer():IsValid() then
		if not vgui.MouseEnabled then
		local screen = LocalPlayer():GetPos():ToScreen()
		local Mx, My = gui.MousePos()
		LocalPlayer():SetEyeAngles(Vector(0, Mx - screen.x, screen.y - My):Angle())

Right now I have a cam where I can see the player in a 2D perspective, what I’m triying to do is to move the angle of the player up and down using the mouse, right now the mouse appears and works, but the player doesn’t change angles.

The code on the weapon was because I wanted to see what was the problem because it didn’t appeared and I’m sure is because of this piece of code I posted here right now, but I don’t know where is the problem or why doesn’t do what I want

Edit: I saw the error, It’s solved, thanks for the help guys xDDDD