Hello everybody! As I am still working with networking, I came across a problem with net.SendToServer, in a certain case, it doesn’t do anything. Let me give an exemple
Here is my client side file
net.Start('SendToServer') net.WriteString('Test string.') net.SendToServer()
Then I have my server side file:
util.AddNetworkString('SendToServer') net.Receive('SendToServer', function() local str = net.ReadString(); print('Received the string ' .. str) -- Should print the string, but nothing happens. end)
In this case, nothing happens, and I checked, my client side file is included without any problems.
But, if I put my net message in a console command and then run it, it works.
concommand.Add('cl_sendnetmsg', function() net.Start('SendToServer') net.WriteString('Test string.') net.SendToServer() -- This time, it sends it to the server. end)
In this case, if I run my console command “cl_sendnetmsg”, it works, and the networked string is printed server side.
Maybe the net.SendToServer is sent before the client can send net messages to the server. I know that a timer would fix it, but it wouldn’t be a good way of fixing it. I just would like to know why the message isn’t sent to the server and the bets “moment” (hook?) to send the message to my server. Thank you in advance!