Stencil Draws Over Everything

My stencils are drawing over every model, including my viewmodel.
What am I doing wrong here?

[lua]
function ENT:DrawPortal()
local viewent = GetViewEntity()
local pos = ( IsValid( viewent ) and viewent != LocalPlayer() ) and GetViewEntity():GetPos() or EyePos()

if IsInFront( pos, self:GetPos(), self:GetForward() ) and self:GetNWBool("Potal:Activated",false) then
	
	cam.Start3D(pos,EyeAngles())
	render.ClearStencil() -- Make sure the stencil buffer is all zeroes before we begin
	render.SetStencilEnable( true )
	render.SetStencilWriteMask(255)
	render.SetStencilTestMask(255)
	render.SetStencilFailOperation( STENCILOPERATION_KEEP )
	render.SetStencilZFailOperation( STENCILOPERATION_KEEP )  -- Don't change anything if the pixel is occoludded (so we don't see things thru walls)
	render.SetStencilPassOperation( STENCILOPERATION_REPLACE ) -- Replace the value of the buffer's pixel with the reference value
	render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_ALWAYS ) -- Always replace regardless of whatever is in the stencil buffer currently

	render.SetStencilReferenceValue( 1 )
   
	local percentopen = self.openpercent
	self:SetModelScale( percentopen,0 )
	self:DrawModel()
	
	render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
	
	local portaltype = self:GetNWInt( "Potal:PortalType",TYPE_BLUE )
	local ToRT = portaltype == TYPE_BLUE and texFSB or texFSB2

	PortalMaterial:SetTexture( "$basetexture", ToRT )
	render.SetMaterial( PortalMaterial )
	render.DrawScreenQuad()
   
	render.SetStencilEnable( false )
	cam.End3D()

end

end
hook.Add(“PostDrawOpaqueRenderables”,“DrawPortals”, function()
for k,v in pairs(ents.FindByClass(“prop_portal”))do
v:DrawPortal()
end
end)[/lua]

Try PreDraw… instead of PostDraw( which is going to draw after everything and be potentially on top of weapons, etc. )

Tried that, same result. It’s drawing it as a screen quad, like it was part of my HUD.

Does it draw through walls too? If so, check IgnoreZ.

No it doesn’t go through the wall.

I am really not sure but it might be render.SetStencilPassOperation( STENCILOPERATION_REPLACE ), try changing the enum or reference value

Solved. Called it in PostDrawViewModel.