Problems with net.SendToServer()

Hey FacePunch community !

I get a problem with my net.SendToServer…

I’m testing a swep, so here the code :

cl_init.lua



if not LocalPlayer():canAfford(amount_floor) then
	net.Start("fwlt")
		net.WriteString("Testing")
	net.SendToServer()
	return ""
end


init.lua



-- Adding the netstring
util.AddNetworkString("fwlt")

-- When receive the net 
net.Receive("fwlt", print("success"))


I think my code is correct but nothing apear…

I’m sure the if is working, I’ve tested the code with only a print(“success”) in the condition and it was working :confused:

I reallllly hope someone can help me !

Thanks a lot in advance,
Gaby

try this:


net.Receive( "fwlt", function( _Length, _Player )
      print( "success" )
end)

You’re passing both the length and the player into the print function, so in reality it will probably break.

While your code snippet is indeed the correction required, your reasoning is wrong. print(“success”) doesn’t return a function that will print success, it calls the function print with argument success, and returns nil. This means that the second argument in net.Receive is nil, and not a function that can handle net messages.

Hey guys !

Thanks you so much, it’s working now.

I think it can be cool to explain like that on the gmod wiki. Cuz for beginners it’s not really clear ^^

Thanks a lot again,

Gaby