net library "attempt to call field 'AddNetworkString' (a nil value)"
6 replies, posted
I get a lua error and my code doesn't work and i don't know what is wrong
[ERROR] addons/serverstuff/lua/autorun/sv_mlgcodingserver.lua:1: attempt to call field 'AddNetworkString' (a nil value)
1. unknown - addons/serverstuff/lua/autorun/sv_mlgcodingserver.lua:1
Serverside:
util.AddNetworkString( "custom1" )
net.Receive( "custom1", function( len, ply )
local msg = net.ReadString()
net.Start( "custom1" )
net.WriteString(msg)
net.Broadcast()
end )
clientside:
net.Receive( "custom1", function( len )
local msg = net.ReadString()
chat.AddText(msg) -- Color(190, 190, 190),
end )
hook.Add( "OnPlayerChat", "customchat", function( ply, strText, bTeam, bDead )
if ( ply != LocalPlayer() ) then return end
net.Start("custom1")
net.WriteString(strText)
net.SendToServer()
end )
Just because you add a "sv_" in the file name, it's not serverside.
Do a SERVER check or put it to lua/autorun/server.
The second option is the best, the client doesn't have to download the file then, can't leak it and your code is shorter.
Listen,
I think you don't understand the power of the net library, yet.
I would JUST make your complete code serverside.
Otherwise enjoy messages being spammed in your server, because someone funny exploits your netmessage. (YOU NEED a timer, because otherwise, they'll spam messages for the whole server)
of all, this is exploitable, like mcNuggets already said.
You can either put a server check in the code, or you put the serverside code in this path addons/serverstuff/lua/autorun/server/sv_mlgcodingserver.lua
(inside autorun is another folder called server, put the lua file in there)
Since you execute this file on autorun you have to set the following:
if(SERVER) then
-- Your code here
end
Okay I totally forgot to make the server side folder :0 thanks and i will make it less exploitable as u say
Why not use this? GM:PlayerSay
My new code uses that and works good
Sorry, you need to Log In to post a reply to this thread.