swep help required


I am working on a swep that supposingly functions as a flashlight, but brighter in a way,
it is for my roleplay servers police force,

function SWEP:PrimaryAttack()
	if ( !self:CanPrimaryAttack() ) then return end
         local light = DynamicLight(LocalPlayer():EntIndex())
          if ( light ) then
          	light.pos = "ValveBiped.Bip01_R_Hand"
          	light.r = 255
	     	light.g = 255
	    	light.b = 255
	        light.brightness = 10
                light.Decay = 1000
         	light.Size = 256


the code given above is certainly wrong but I dont know what is wrong or what I should do instead

You need to call DynamicLight in a think hook or something similar.