Send a string from a server file to a client file

Soo, Im getting to learn LUA and I have stumbled across something I cant seem to figure out.

My question -

How would you send a string from a server file to a client file, and then use that string inside the client file?

Example of what I am looking to do -

Player 1 types- “/msg this is a test”

Once the command and message is typed out,then that message is printed onto the gui, for example a HUD at the bottom of the screen.

Soo, pretty much I am wanting to a setup a command that prints a message onto a HUD ingame.

Any help is appreciated, thanks in advanced for any help!

Do you know of any detailed tutorials of setting this up correctly? Ive tried and tested with it up until a point where I no longer get errors with it, however the string isnt sending across for what ever reason. D:

Thanks again.

An example, if it helps (shared)
[lua]
if SERVER then
util.AddNetworkString(“example_1”)

hook.Add( "PlayerSay", "some_unique_name5123", function( ply, text, _ )
	
	if text == "!test" then
		net.Start( "example_1" )
		net.WriteString( text )
		net.Send( ply )
	end
	
end	)

else

net.Receive( "example_1", function( len )
	
	local str = net.ReadString()
	
	-- open menu, str = your string
	
end	)

end
[/lua]

Here’s a decent video tutorial - https://www.youtube.com/watch?v=ODlGyS6lR1M
Also, you should share your code next time! We can help find the problem. :happy:

Thanks for the snippet, Ill try and figure it out with what you have provided, if not ill snippet what i have so far.

+1 for the help =]

Ok so ive got the connection to the server and client side sorted, However now my next step is to get the message to print to a simpletext or label that is on my hud, I can see you have wrote the snippet, is there anything else that must be added to do such thing?

Sorry for soo many questions D:.

Thanks in advanced!

replace ‘-- open menu, str = your string’ with your desired HUD code.

Thanks for the help! Ill see what I can do now ;D

+1 for the help!