Using net to send chat.AddText

So iv been just work so f***ing hard on doing something so simple and iv only got one thing working using net library.

This is the code that im trying to put into net.


concommand.Add( "1server_1", function( ply, cmd, args )
if (ply == LocalPlayer() and groups[ LocalPlayer():GetUserGroup() ] ) then

local SMSG = vgui.Create( "DFrame" )
SMSG:SetSize( 249, 186 )
SMSG:Center()
SMSG:MakePopup()
SMSG:SetTitle( "Post an Announcment!" )
SMSG:SetBackgroundBlur( true ) 
SMSG:SetPaintShadow( true )
--SMSG:SetBackgroundColor( BGPanColor )

local SERVERNAME = vgui.Create( "DTextEntry", SMSG ) 
SERVERNAME:SetPos( 18, 45 )
SERVERNAME:SetSize( 211, 26 )
SERVERNAME:SetText( "CommunityName" )
SERVERNAME:SetEditable ( true )

local MESSAG = vgui.Create( "DTextEntry", SMSG ) 
MESSAG:SetPos( 18, 90 )
MESSAG:SetSize( 211, 26 )
MESSAG:SetText( "Type out a server message here" )
MESSAG:SetEditable ( true )
MESSAG.OnEnter = function( self )
timer.Create('advert1', 1, 1, function()
chat.AddText( servercommuntiycolor, '[', servercommuntiycolor, SERVERNAME:GetValue(), ']', messagecolor, ' ', messagecolor, self:GetValue() )
end)
	end
		end
				end)

Here is the snip it iv done so far that works but I am not sure if it will send to all clients. Not the local client.
Client Side


net.Receive( 'battlestat', function()
    surface.PlaySound( "battle_stations.wav" )
    chat.AddText(servercommuntiycolor, '[ATTENTION] ', messagecolor, 'Everyone to your battle stations!')
		end)

Server Side


util.AddNetworkString( 'battlestat' )

concommand.Add( "battle_stations", function( ply, cmd )
net.Start( 'battlestat' )
   net.Send( ply )
   net.Broadcast()
end)

Any help on making both of these send to all of the players?

You’re using net wrong. You’re starting a net message, sending it to the player that executed the command (ply inside of the concommand) and then trying to broadcast it when it is just sent to one player.
You should remove the net.Send(ply) line and it should work. And if i was you I would add some checks to see if the player that executes the command is an admin or else to prevent spam from normal users.

Also, i recommend you to take a look at this guide as well to understand properly how net works.

[EDITLINE]Edit[/EDITLINE]

Ninja’d too

Remove net.Send( ply ).

[editline]23rd July 2017[/editline]

Ninja’d

Thank you very much, and Im not hip with the whole Ninja’d meme. What does it mean?

Ninja’d = Someone posts the same thing right before you did.

or you post it before they did.
Anyways, as i also said you should add Security checks as for example checking if the player sending the net message is an admin, due to some “script kiddies” discovering and exploiting this, spamming everyone’s chat and sound.

Done.

[editline]24th July 2017[/editline]

Ok so turns out it does work im just not to sure how to get the values from the Entrys

Client Side


-- local servername = SERVERNAME:GetValue() -- This is simply the textentry's thingy mabob? You know just dont touch it how bout dat. :/

---------------------------=== Local Colors Town ===------------------------------\
local BGPanColor = Color(155, 155, 155, 150)
local servercommuntiycolor = Color(188, 13, 13) -- Whats the color you want for the Server Comunity Name.  Auto is red-ish                          
local messagecolor = Color(255, 255, 255)	-- Whats the message color you want? Auto is white
local groups = { 
    ["owner"] = true,
	["founder"] = true,
	["developer"] = true
}

-----------=== Train is leaving now, get the fuck off and leave.===---------------/
-- *TRANSLATION* Dont touch down there. Thats the no no square.
net.Receive( 'battlestat', function()
    surface.PlaySound( "battle_stations.wav" )
    chat.AddText(servercommuntiycolor, '[ATTENTION] ', messagecolor, 'Everyone to your battle stations!')
		end)



concommand.Add( "1server_1", function( ply, cmd, args )
if (ply == LocalPlayer() and groups[ LocalPlayer():GetUserGroup() ] ) then

local SMSG = vgui.Create( "DFrame" )
SMSG:SetSize( 249, 186 )
SMSG:Center()
SMSG:MakePopup()
SMSG:SetTitle( "Post an Announcment!" )
SMSG:SetBackgroundBlur( true ) 
SMSG:SetPaintShadow( true )
--SMSG:SetBackgroundColor( BGPanColor )

local SERVERNAME = vgui.Create( "DTextEntry", SMSG ) 
SERVERNAME:SetPos( 18, 45 )
SERVERNAME:SetSize( 211, 26 )
SERVERNAME:SetText( "CommunityName" )
SERVERNAME:SetEditable ( true )

local MESSAG = vgui.Create( "DTextEntry", SMSG ) 
MESSAG:SetPos( 18, 90 )
MESSAG:SetSize( 211, 26 )
MESSAG:SetText( "Type out a server message here" )
MESSAG:SetEditable ( true )
MESSAG.OnEnter = function()
net.Start( "broadcastmsg" )
net.SendToServer()
	end
		end
			end)


			--chat.AddText( servercommuntiycolor, SERVERNAME:GetValue(), messagecolor, self:GetValue() )

Server Side


util.AddNetworkString( 'battlestat' )
util.AddNetworkString( "broadcastmsg" )

local groups = { 
    ["owner"] = true,
	["founder"] = true,
	["developer"] = true
}


concommand.Add( "battle_stations", function( ply, cmd )
if (groups[ ply:GetUserGroup() ] ) then
net.Start( 'battlestat' )
   net.Broadcast()
end
    end)




net.Receive( "broadcastmsg", function()
net.Broadcast()
print("Hello person reading this. Welcome!")
BroadcastLua( [[chat.AddText(Color( 223, 123, 123 ),'Hello')]] )
--BroadcastLua( [[chat.AddText( servercommuntiycolor, SERVERNAME:GetValue(), messagecolor, self:GetValue())]] )
end)

[editline]24th July 2017[/editline]

Any help on the situation above? ^ Im seeing people come and leave. Im not sure if its cause there not seeing the edited part.

You need to network the values of the fields from the client to the server, and back again from the server to all of the clients.
As i said the other day, to send specific data fields with net as Strings or Booleans or else, you should read THIS GUIDE.

Also, next time use proper indentation.

Message value from text entry.Don’t forget to add security.

Clientside



MESSAG.OnEnter = function()
	net.Start( "MessageValue" )
	net.WriteString( MESSAG:GetValue() )
	net.SendToServer()
end


Serverside



util.AddNetworkString( "MessageValue")
net.Receive( "MessageValue", function( len, ply )
local val = net.ReadString()
if val != nil then
print("Message text is " .. val)
end
end )


I plan on reading it and doing everything on a day I am free. Or just free time. RN Im just free balling it.

[editline]25th July 2017[/editline]

I might just keep this open so people who need help can post on here. I might put this script on git hud. Idk