Why doesn't this work

I’m trying to make a gun that makes entities ignore the depth buffer. The effect that plays when an entity is spawned uses the exact same method; setting entity.RenderOverride to a function.
BUT IT JUST WON’T WORK FOR ME

SHARED:



SWEP.Author = "For Science"
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.Category = "Other"

SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.ViewModel = "models/weapons/c_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"

SWEP.UseHands = true

SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"

function SWEP:NoDepth()

	cam.IgnoreZ(true)
	self:DrawModel()
	cam.IgnoreZ(false)

end

function SWEP:PrimaryAttack()

	local hitentity = self.Owner:GetEyeTrace().Entity

	if (CLIENT) then

	hitentity.RenderOverride = self.NoDepth

	end

end

SERVER:



AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")

SWEP.Weight = 1
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false

CLIENT:



include("shared.lua")

SWEP.PrintName = "NoDepthGun"
SWEP.Slot = 1
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false

For one, this is only being called one time, I believe you need to call it every time the model is rendered in order for it to have any real effect here. For two, you’re calling a render function in a shared part of the code…

It’s setting the function “ENT:RenderOverride()” to the “NoDepth” function that I defined. It would seem strange that I would have to keep setting the function each think. And shared code is shared between the server and the client, and I have “if (CLIENT) then…” to specify that it needs to be run on the client. I have already tried it in the client code only, and I got the same results.