pls help me[Foundation Keycard Scanner]

When i open the menu from the foundation scanner
and press to clearence 4(level 4) to added levels
and close the menu and open it back is the clearence 4(level 4)
agian in non added levels
here is the code:


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

util.AddNetworkString( "netFKeycardSMenu" )
util.AddNetworkString( "netFKeycardSAddLevel" )
util.AddNetworkString( "netFKeycardSRemoveLevel" )
util.AddNetworkString( "netFKeycardSpawn" )
util.AddNetworkString( "netFKeycardHackSpawn" )
util.AddNetworkString( "netFKeycardAdminSpawn" )

net.Receive( "netFKeycardAdminSpawn", function( len, ply )
	local ent = net.ReadEntity()
	if not IsValid( ply ) or not IsValid( ent ) then return end
	if ent:GetStatus() ~= ent.Status_None then return end
	
	local keycard = ents.Create( "ent_foundationscanner" )
	keycard:SetPos( ent:LocalToWorld( Vector(-7.5, 0, -0.1) ) )
	keycard:SetAngles( ent:LocalToWorldAngles( Angle(0, 0, 0) ) )
	keycard:SetParent( ent )
	keycard:Spawn()

	timer.Simple( 2, function()
		if not IsValid( ent ) or not IsValid( keycard ) then return end
		keycard:Remove()
	end )

	ent:Access( true )
end )

net.Receive( "netFKeycardSpawn", function( len, ply )
	local ent = net.ReadEntity()
	if not IsValid( ply ) or not IsValid( ent ) then return end
	if ent:GetStatus() ~= ent.Status_None then return end
	
	local keycard = ents.Create( "ent_keycard" )
	keycard:SetPos( ent:LocalToWorld( Vector(-7.5, 0, -0.1) ) )
	keycard:SetAngles( ent:LocalToWorldAngles( Angle(0, 0, 0) ) )
	keycard:SetParent( ent )
	keycard:Spawn()

	timer.Simple( 2, function()
		if not IsValid( ent ) or not IsValid( keycard ) then return end
		
		keycard:Remove()
	end )

	ScanCard( ply, ent )
end )

net.Receive( "netFKeycardHackSpawn", function( len, ply )
	local ent = net.ReadEntity()
	if not IsValid( ply ) or not IsValid( ent ) then return end
	if ent:GetStatus() ~= ent.Status_None then return end

	local keycard = ents.Create( "ent_hacking_keycard" )
	keycard:SetPos( ent:LocalToWorld( Vector(-7.5, 0, -0.1) ) )
	keycard:SetAngles( ent:LocalToWorldAngles( Angle(0, 0, 0) ) )
	keycard:SetParent( ent )
	keycard:Spawn()

	ply:StripWeapon( "weapon_hacking_keycard" )
	ent:EmitSound( "buttons/button18.wav" )
	ent:SetStatus( ent.Status_Hacking )

	timer.Create( "KS_Beep", 0.5, 0, function()
		if not IsValid( ent ) or not IsValid( keycard ) then
			if IsValid( ent ) then ent:SetStatus( ent.Status_None ) end

			if IsValid( ply ) then
				ply:Give( "weapon_hacking_keycard" )
			end

			return
		end

		ent:EmitSound( "buttons/button17.wav" )
	end )

	timer.Create( "KS_Beep2", 1.5, 0, function()
		if not IsValid( ent ) or not IsValid( keycard ) then return end

		ent:EmitSound( "buttons/button17.wav" )
	end )

	timer.Simple( KS_HackingTime, function()
		if not IsValid( ent ) or not IsValid( keycard ) then return end
		ply:Give( "weapon_hacking_keycard" )

		timer.Destroy( "KS_Beep" )
		timer.Destroy( "KS_Beep2" )

		ent:SetStatus( ent.Status_None )
		keycard:Remove()

		ent:Access( true )
	end )
end )

net.Receive( "netFKeycardSAddLevel", function( len, ply )
	local ent = net.ReadEntity()
	local AddedLevel = net.ReadEntity()
	
	table.insert( ent.KeycardSData.AllowedLevels, AddedPly )
end )

net.Receive( "netFKeycardSRemoveLevel", function( len, ply )
	local ent = net.ReadEntity()
	local RemovedLevel = net.ReadEntity()
	
	for k, v in pairs( ent.KeycardSData.AllowedLevels ) do
		if v == RemovedLevel then
			table.remove( ent.KeycardSData.AllowedLevels, k )
			break
		end
	end
end )

function ScanCard( ply, ent )
	if not IsValid( ply ) or not IsValid( ent ) then return end
	if ent:GetStatus() ~= ent.Status_None then return end
	if ply:EyePos():Distance( ent:GetPos() ) >= 120 then return end

	ply:StripWeapon( "weapon_keycard" )
	ent:EmitSound( "buttons/button14.wav" )
	ent:SetStatus( ent.Status_Scanning )

	timer.Simple( 2, function()
		if not IsValid( ent ) then return end
		local allowedLevels = ent.KeycardSData.AllowedLevels or {}
		if ply == ent.KeycardSData.Owner or table.HasValue( allowedLevels, ply ) then ent:Access( true ) else ent:Access( false ) end
	end )

	timer.Simple( 2, function() ply:Give( "weapon_keycard" ) end )
end

function ENT:Initialize()
	self:SetModel( "models/card/keycard_scanner.mdl" )
	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )
	self:SetUseType( SIMPLE_USE )
	
	local phys = self:GetPhysicsObject()
	if phys:IsValid() then phys:Wake() end

	if not self.KeycardSData then self.KeycardSData = self:GetData() end
end

function ENT:Use( activator, caller )
	if not IsValid( activator ) then return end
	if activator ~= self.KeycardSData.Owner then return end

	net.Start( "netFKeycardSMenu" )
		net.WriteEntity( self )
		net.WriteTable( self.KeycardSData )
	net.Send( activator )
end

function ENT:Access( granted )
	local length, initdelay, delay, owner, key

	if granted then
		self:SetStatus( self.Status_Granted )

		length = self.KeycardSData.LengthGranted
		initdelay = self.KeycardSData.InitDelayGranted
		delay = self.KeycardSData.DelayGranted
		owner = self.KeycardSData.Owner
		key = tonumber( self.KeycardSData.KeyGranted ) or 0
	else
		self:SetStatus( self.Status_Denied )

		length = self.KeycardSData.LengthDenied
		initdelay = self.KeycardSData.InitDelayDenied
		delay = self.KeycardSData.DelayDenied
		owner = self.KeycardSData.Owner
		key = tonumber( self.KeycardSData.KeyDenied ) or 0
	end

	timer.Simple( math.max(initdelay + length + delay * 0.25, 2), function()
		if IsValid( self ) then
			self:Reset()
		end
	end )

	timer.Simple( initdelay, function()
		if IsValid( self ) then
			if IsValid( self ) and IsValid( owner ) then
				numpad.Activate( owner, key, true )
			end

			timer.Simple( length + delay, function()
				if IsValid( self ) and IsValid( owner ) then
					numpad.Deactivate( owner, key, true )
				end
			end )
		end
	end )

	if granted then
		self:EmitSound( "buttons/button9.wav" )
	else
		self:EmitSound( "buttons/button11.wav" )
	end
end

function ENT:SetData( data )
	self.KeycardSData = data

	self:Reset()
end

function ENT:GetData()
	return self.KeycardSData
end

function ENT:Reset()
	self:SetStatus( self.Status_None )
end

This shouldn’t be in this section