net.Send doesnt works

the net.Send at


if table.Count(tableticket) > 0 then
    FindsAPlayerToday(ply ,"superadmin", "admin", "helper")
	net.Start("adminalert")
	net.Send(player.GetByID(1))
	print("sent data -adminalert- to ")
end

doesnt works

my current code [SERVERSIDE]:


   AddCSLuaFile ("shared.lua");

function FindsAPlayerToday( ply, target, target2, target3 )
         v = {}
		 print("players found"..v.." with "..n)
		  if table.Count(v) == 0 then n = 1 end
		 if table.Count(v)>0 then n = table.Count(v)+1 end
		 for i = 1,table.Count(player.GetAll()) do
		           if player.GetByID(i):GetUserGroup() == target1 or  player.GetByID(i):GetUserGroup() == target2 or  player.GetByID(i):GetUserGroup() == target3 then
				                       v[n] = player.GetByID(i)
				   end
				   
		 end
         
		 end	
   
   
   if SERVER then
  howmuch = 1
  tableticket = {}
  util.AddNetworkString("openticket")
  util.AddNetworkString("stringcall")
  util.AddNetworkString("adminalert")

 
  
  net.Receive("Stringcall" , function(len , ply)
            print("got string data from client. count is : "..table.Count(tableticket)..table.ToString(tableticket))
			if table.Count(tableticket) == 0 then
			tableticket[1] = net.ReadString() 
			
			end
			if table.Count(tableticket)>0 then
			howmuch = howmuch+1
			tableticket[howmuch] = net.ReadString() end
			
			
			
			 
 
 end)
 -- if there is a alert sends it to all admins
 if table.Count(tableticket) > 0 then
    FindsAPlayerToday(ply ,"superadmin", "admin", "helper")
	net.Start("adminalert")
	net.Send(player.GetByID(1))
	print("sent data -adminalert- to ")
end


  hook.Add("PlayerSay", "chatticket", function(ply, text, public)
if text == "/ticket" then
net.Start("openticket")
net.Send(ply)
print("sent data -ticket- from client")
end
end)
  

  end

player.GetByID(1) will not always work if you are alone on the server. Use Entity(1) - That will select the first player.

no it didnt solve the problem

You are trying to send the net message before the server has fully started. Use InitPostEntity or Initialize hooks to send your message.


if table.Count(tableticket) > 0 then
    for k,v in pairs(player.GetAll()) do
if v:IsAdmin() or v:IsUserGroup("helper") then
	net.Start("adminalert")
	net.Send(v)
	print("sent data -adminalert- to " ..v:Nick())
end
end
end

I’m not that good with Lua but this should work.

Edit: Nevermind, I see now where the issue lies.

i have tried it but still not working. And i cant understand why only “net.Start(“adminalert”)” doesnt works

other net.Start() funchtions are working well

As I told you, you are trying to sent the message to player.GetByID(1), which at the very first second of server’s life, will return NOTHING or something like that. Use Entity(1) and send the net message from one of the two hooks I posted above.

i have tried all of them but still not working :confused:

my current code :


   AddCSLuaFile ("shared.lua");

function FindsAPlayerToday( ply, target, target2, target3 )
         v = {}
		 print("players found"..v.." with "..n)
		  if table.Count(v) == 0 then n = 1 end
		 if table.Count(v)>0 then n = table.Count(v)+1 end
		 for i = 1,table.Count(player.GetAll()) do
		           if player.GetByID(i):GetUserGroup() == target1 or  player.GetByID(i):GetUserGroup() == target2 or  player.GetByID(i):GetUserGroup() == target3 then
				                       v[n] = player.GetByID(i)
				   end
				   
		 end
         
		 end	
   
   
   if SERVER then


  
  
  howmuch = 1
  tableticket = {}
  util.AddNetworkString("openticket")
  util.AddNetworkString("stringcall")
  util.AddNetworkString("adminalert")

 
  
  net.Receive("Stringcall" , function(len , ply)
            print("got string data from client. count is : "..table.Count(tableticket)..table.ToString(tableticket))
			
			if table.Count(tableticket) == 0 then
			tableticket[1] = net.ReadString() 
			
			end
			if table.Count(tableticket)>0 then
			howmuch = howmuch+1
			tableticket[howmuch] = net.ReadString() end
			
			
			
			 
 
 end)
-- if there is a alert sends it to all admins
hook.Add("Initialize", "servercheck", function()
 if table.Count(tableticket) > 0  then
    FindsAPlayerToday(ply ,"superadmin", "admin", "helper")
	net.Start("adminalert")
	net.Send(Entity(1))
	print("sent data -adminalert- to ")

end
end)


  hook.Add("PlayerSay", "chatticket", function(ply, text, public)
if text == "/ticket" then
net.Start("openticket")
net.Send(ply)
print("sent data -ticket- to client "..ply:Nick())
end
end)

  hook.Add("Initialize", "servercheck", function()
  

  
  
  
  
 end






You should send a message only when you know whom to.

I think you wanted to make something like this:


net.Receive("Stringcall" , function(len , ply)
    print("got string data from client. count is : "..table.Count(tableticket)..table.ToString(tableticket))
    
    table.insert(tableticket, net.ReadString())
    
    for k, v in pairs(player.GetAll()) do
        if v:IsAdmin() or v:IsUserGroup("helper") then
            net.Start("adminalert")
            net.Send(v)
            print("sent data -adminalert- to ", v)
        end
    end
 end)

It worked! Thanks for helping .