Entity Networking Issue

Hey, so I created an entity, everything seemed to be working perfectly until I found a bug which I do not know how to fix, basically when the entity is interacted with a vgui menu is supposed to popup for the player who used it, however when any player interacts with it they do not get a vgui menu popup, instead the vgui menu shows up on my screen, I’ve been trying the figure out why this happens but made literally no progress towards solving it.

init.lua (Networking section)


util.AddNetworkString("fieldAgentDisguise")
util.AddNetworkString("ertDisguise")
util.AddNetworkString("troDisguise")
util.AddNetworkString("mtfDisguise")
util.AddNetworkString("interacted")



function ENT:Use(a,c) 

for k, v in pairs (whiteList) do

if a:Team() == v then

net.Start("interacted")
net.Send(Entity(1))

cl_init.lua




include("shared.lua")

function ENT:Draw()
	self:DrawModel()	
end

net.Receive("interacted", function(len, ply)
print("Client Running!")
local disguiseUI = vgui.Create("DFrame")
disguiseUI:SetSize(310,200)
disguiseUI:SetVisible(true)
disguiseUI:Center()
disguiseUI:MakePopup()
disguiseUI:SetTitle("Disguise Kit")
disguiseUI.Paint = function(s, w, h)
	draw.RoundedBox(5,0,0,w,h,Color(0,0,0))
	draw.RoundedBox(5,4,4,w-8,h-8,Color(255,255,255))
end

It’s because you’re sending the net message to Entity( 1 ) rather than the player who “activated” the entity.

I’m also assuming that’s a snippet of your ENT.Use function, otherwise, there are errors.

So, rather than sending it to Entity( 1 ), send it to “a”, which is what you’ve named the Entity Activator.

This causes an error :confused:

“[ERROR] lua/entities/disguise_kit/init.lua:57: bad argument #1 to ‘Entity’ (number expected, got userdata)”

Stop calling the function Entity.

Just do: net.Send( a ) where a is your activator, which comes straight from the function ENT.Use itself.

Have a look at these pages: