Sending A colored Chat Message to a single user.

Hi I am trying to send a colored chat message to a single player from the server.

I am using ply:PrintMessage( HUD_PRINTTALK, “TEXT”) but I cant add any color to it, and chat.AddText is client side so I am a bit lost on this one.

Can anyone help out?

Use the net library.


Whoops, disregard this.

How do you use he is using ulx?

Yeah just realised. My bad.

So far I just got even more confused…sorry

chat.AddText is the function to create colored chat.

The problem is, it’s client-side only and you cannot run it on the server, you must send it to the client.


[lua]if SERVER then – Let’s start Server-side networking
util.AddNetworkString(“Text”) – Declare the name of the network name (you gotta name it, basically)
hook.Add(“PlayerInitialSpawn”, “Text”, function(ply) – Add a function to a hook
net.Start(“Text”) – Start your message
net.WriteString(“Received!”) – Write a string
net.WriteEntity(ply) – Write an entity
print(“Yay it went through”) – debugging
net.Broadcast() – Send it to everyone on the server
end) – End the hook
end – end server-sided lua

if CLIENT then – Start client-side networking
local color = Color(255,0,0,255) – Define a color shall we?
net.Receive(“Text”, function() – Receive a net string sent by the server
str = net.ReadString() – string = the string we wrote and sent
ply = net.ReadEntity() – ply = the entity we wrote and sent
print(tostring(ply)) – debug
chat.AddText(color, ply:GetName() … " has connected! Your message has been " … str)
– Let’s now write a colored string on the chat!
end) – End the net.Receive function
end – End client-side lua!