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!