Error with rendering beam for everyone.

I’m trying to make it so everyone in the server renders a beam at the same time, and to do that, I wrote the following.

Note: The beam need to be rendered on one or more people. with the maximum amount of entities that will draw beams being three.

In server script:

               net.WriteEntity( ent ) --defined earlier

In cl_init:

net.Receive("draw", function()
   local ent = net.ReadEntity()
   local mat = Material("cable/blue_elec")
   local view = shootingent:GetViewModel()
   local obj = view:LookupAttachment( "muzzle" )
   function startDoodling()
   local startpos = view:GetAttachment(obj).Pos
   local endpos = ent:GetEyeTrace().HitPos
   local magnitude = startpos:Distance(endpos)
   render.SetMaterial( mat )
   render.DrawBeam( startpos , endpos , 5 , 1 , 1 , Color(255,255,255))
   hook.Add("PostDrawOpaqueRenderables", "Doodles", startDoodling)

And I am getting this error:

[ERROR] gamemodes/terrortown/gamemode/cl_init.lua:384: Tried to use a NULL entity!
  1. LookupAttachment - [C]:-1
   2. func - gamemodes/terrortown/gamemode/cl_init.lua:384
    3. unknown - lua/includes/modules/net.lua:32

Can anyone help?

I’m thinking that I might just have to have three different net messages being sent for each of the three people potentially shooting the beams, but that causes the problem of the beams not being rendered in the same frame, and therefore overriding each other. That means that this ideally needs to be in one net message.

You’re calling shootingent:GetViewModel but shootingent isn’t defined in the code you posted.

[editline]17th May 2015[/editline]

You probably meant to use just ‘ent’

That was an error I made while trying to make the code intelligible for people that aren’t me. It is not like that in the actual code.

lol then say that it is just so some people understand it, you’ll make people think that you having not defined shootingent is the problem