Toggling my client script

I have a simple 3rd person script that i use for messing around on servers but i want to make it where i can turn it off while im on a server.Here’s my code::


function MyCalcView(ply, origin, angles, fov)
  

      
    local viewdistance = 126;  
      
    local vec = ply:GetAimVector();  
    local org = (vec * -viewdistance);  
      
    local tr = util.QuickTrace(origin, org, ply);  
      
    org = ((tr.Hit && (tr.HitPos + (vec * 8))) || tr.HitPos);  
      

    local view = {};
    view.origin = org;  
    view.angles = angles;  

    return view;  
      
end  

hook.Add("CalcView", "MyCalcView", MyCalcView)
 
hook.Add("ShouldDrawLocalPlayer", "MyHax ShouldDrawLocalPlayer", function(ply)
        return true
end)


Just make a check for a variable etc.

local On = true

and then make a if statement that checks if On is true.
Then make a console command that toggles that variable

but don’t console commands have to be on the server?

nope they can be clientside to


local On = true  
function MyCalcView(ply, origin, angles, fov)
  

    if(on)then  
    local viewdistance = 126;  
      
    local vec = ply:GetAimVector();  
    local org = (vec * -viewdistance);  
      
    local tr = util.QuickTrace(origin, org, ply);  
      
    org = ((tr.Hit && (tr.HitPos + (vec * 8))) || tr.HitPos);  
      

    local view = {};
    view.origin = org ;  
    view.angles = angles;  

    return view;  
    end
	
	  
end  

hook.Add("CalcView", "MyCalcView", MyCalcView)
 
hook.Add("ShouldDrawLocalPlayer", "MyHax ShouldDrawLocalPlayer", function(ply)
        return true
end)

function toggle()
 if (on == true)then
 on = false
 else
 on = true
 end
end
concommand.Add( "toggle", toggle )


this is what i have will that work? EDIT:: I need to know how to reset your view

[lua]
hook.Add(“ShouldDrawLocalPlayer”, “MyHax ShouldDrawLocalPlayer”, function(ply)
return On
end)
[/lua]

that will only hide the player not set the view back to 1st person

also when i try running the script it gives the error
:1: ‘=’ expected near ‘<eof>’

[lua]local on = true
function MyCalcView(ply, origin, angles, fov)

if(on)then  
local viewdistance = 126;  
  
local vec = ply:GetAimVector();  
local org = (vec * -viewdistance);  
  
local tr = util.QuickTrace(origin, org, ply);  
  
org = ((tr.Hit && (tr.HitPos + (vec * 8))) || tr.HitPos);  
  

local view = {};
view.origin = org ;  
view.angles = angles;  

return view;  
end

end

hook.Add(“CalcView”, “MyCalcView”, MyCalcView)

hook.Add(“ShouldDrawLocalPlayer”, “MyHax ShouldDrawLocalPlayer”, function(ply)
return on
end)

function toggle()
if (on == true) then
on = false
else
on = true
end
end
concommand.Add( “toggle”, toggle )[/lua]

Fixed.

[lua]function toggle()
on = not on
end[/lua]