Having trouble with custom SWEP

Heys guys,

Im having some trouble getting my sleder swep to work. Im trying to get it so that when Slender clicks on a player it will uncloak him and (at the moment) when he clicks again it uncloak him. But i want only the person he clicks on to see him. Im trying my best to learn by myself but im having a lot of trouble. I noted it best i could and would appreciate any help or ideas.

Thank you


 
if SERVER then 


--===========Setting up Network Messages =======================

	AddCSLuaFile ("shared.lua")
	util.AddNetworkString("SLENDY_Init")
	util.AddNetworkString("SLENDY_Cloak")
	util.AddNetworkString("SLENDY_Target_Cloak")

	util.AddNetworkString("SLENDY_Scare_Uncloak")
	util.AddNetworkString("SLENDY_Scare_Target_Uncloak")
	util.AddNetworkString("SLENDY_Scare_LocalPly_Uncloak")

	local ShootSound = Sound("Metal.SawbladeStick") --precaching sound
 
	SWEP.Weight = 1
 
	SWEP.AutoSwitchTo = false
	SWEP.AutoSwitchFrom = false


	--=== Init to get Owner to cloak =====


	net.Receive("SLENDY_Init" ,function (len, ply)
		for k,v in pairs(player.GetAll()) do
			if isTeam(ply,TeamName) then
				ply:SetRenderMode(RENDERMODE_TRANSALPHA)
				ply:SetColor(Color(0,0,0,0))
			end
		end


	end)

---Receiving target from local player for primary and calling uncloak
	net.Receive("SLENDY_Scare_Uncloak" ,

		function (len, ply)
			local target = net.ReadEntity()

			if target == ply then 
				print("Target is you")
		--else
				plys = player.GetAll()
				
				for k,v in pairs(plys) do
							
					net.Start("SLENDY_Scare_Target_Uncloak")
					net.WriteEntity(ply)
					net.Send(target)


			end
		end
	end)


-- Receiving cloak instruction from slender and cloaking
	net.Receive("SLENDY_Cloak",function (len, ply)

				plys = player.GetAll()

				slender = ply


				for i, v in pairs(plys) do
					print(v)
					net.Start("SLENDY_Target_Cloak")
					net.WriteEntity(slender)
					net.Send(v)
				end
				
			
			
		end)


elseif CLIENT then 
 
	
	SWEP.PrintName = "Slender SWEP" -- q menu name
 
	--Sets the position of the weapon in the switching menu 
	--(appears when you use the scroll wheel or keys 1-6 by default)
	SWEP.Slot = 4
	SWEP.SlotPos = 1
 
	--Sets drawing the ammuntion levels for this weapon
	SWEP.DrawAmmo = false
 
	--Sets the drawing of the crosshair when this weapon is deployed
	SWEP.DrawCrosshair = false

	HasAttacked = false -- used to judge whether slendy is cloaked or uncloaked

	
	--====== Sleep: used to stop spamming of cloak/uncloak ==================
	function sleep(n)  -- seconds
		local clock = os.clock
		timer.Simple(n, function() 
			-- body
		end)
	end


	--=========Sends target to server and uncloaks slendy==================

	function SWEP:SendTargetToServ() -- SendTargetToServ function
 
		local ply = self.Owner
		local tr = ply:GetEyeTrace()
		local target = nil
 	
 		if  (tr.Entity:IsPlayer())then 			
 			target = tr.Entity
 		--target:EmitSound(ShootSound) --will play spooky noises
 		else
 				target = ply
 		end


		net.Start("SLENDY_Scare_Uncloak")
		net.WriteEntity(target)
		net.SendToServer()

	end --endfunc




	 
	 
	 
	-- primary attack
	function SWEP:PrimaryAttack()	
		if HasAttacked == false then
			self:SendTargetToServ()
			HasAttacked = true
			print("Primary attack1")
			sleep(5)
		else 
			net.Start("SLENDY_Cloak")
			net.SendToServer()
			HasAttacked = false
			print("Primary attack2")
			sleep(5)
		 
		 	
		
		end

	end
	 
	--secondary attack
	function SWEP:SecondaryAttack()	
		self:SendTargetToServ()
	end



	function SWEP:Reload()

	end
	
	function SWEP:Think()
		
	end

	
	function SWEP:Initialize()		---- init cloak
		local ply = LocalPlayer()
		net.Start("SLENDY_Init")
		net.SendToServer()
	end

	---------------------------------------UNCLOAK------------------------------------------------------

	net.Receive("SLENDY_Scare_Target_Uncloak",function() --- target set slendy uncloak
		local ply = LocalPlayer()	
		local slender = net.ReadEntity()	
		
		slender:SetRenderMode(RENDERMODE_TRANSALPHA)
		slender:SetColor(Color(255,255,255,255))
		

	end)
 	
 	net.Receive("SLENDY_Scare_LocalPly_Uncloak",function() -- local ply set slendy uncloak
 		local ply = LocalPlayer()
		

		ply:SetRenderMode(RENDERMODE_TRANSALPHA)
		ply:SetColor(Color(255,255,255,255))

	end)

	--------------------------------Cloak-------------------------------------------------------------------

	net.Receive("SLENDY_Target_Cloak",function()
		local ply = LocalPlayer()
		local slender = net.ReadEntity()
		slender:SetRenderMode(RENDERMODE_TRANSALPHA)
		slender:SetColor(Color(0,0,0,0))
	end)
	
end


 
--The category that you SWep will be shown in, in the Spawn (Q) Menu 
--(This can be anything, GMod will create the categories for you)
SWEP.Category = "Slender"
 
SWEP.Spawnable = true -- Whether regular players can see it
SWEP.AdminSpawnable = true -- Whether Admins/Super Admins can see it
 
SWEP.ViewModel = "models/weapons/v_hands.mdl" -- This is the model used for clients to see in first person.
SWEP.WorldModel = "" -- This is the model shown to all other clients and in third-person.
 
 

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"
SWEP.TeamName = "Slender"

function isTeam( ply ,teamName ) -- to determin if local player is slender or not
	if team.GetName(ply:Team()) == teamName then
		return true
	else
		return false
	end

end

 


bump

Post to problems that dont need there own thread

Guys, stop pretending that we’ll read and debug shitton of code just because the weapon doesnt work as intended, code one by yourself or pay someone to do that