I did something like this once. First, you’ll have to require the ChatService ModuleScript (DataModel > ServerScriptService > ChatServiceRunner > ChatService
):
local serverScriptService = game:GetService("ServerScriptService")
local chatServiceModule = require(serverScriptService:WaitForChild("ChatServiceRunner").ChatService)
Next, get the ChatSpeaker associated with whoever you’d like to mimic:
local speaker = chatServiceModule:GetSpeaker(name)
If the speaker doesn’t already exist, the player you’re trying to mimic isn’t in the current server. You’ll have to set up a speaker that’s identical to what theirs would be. This will involve a special function that gets their chat colour from their name. We’ll also make them join the All channel:
local nameColors = {
Color3.fromRGB(253, 41, 67), -- BrickColor.new("Bright red").Color,
Color3.fromRGB(1, 162, 255), -- BrickColor.new("Bright blue").Color,
Color3.fromRGB(2, 184, 87), -- BrickColor.new("Earth green").Color,
BrickColor.new("Bright violet").Color,
BrickColor.new("Bright orange").Color,
BrickColor.new("Bright yellow").Color,
BrickColor.new("Light reddish violet").Color,
BrickColor.new("Brick yellow").Color,
}
local function getNameValue(name)
local value = 0
for index = 1, #name do
local cValue = name:sub(index, index):byte()
local reverseIndex = #name - index + 1
if #name % 2 == 1 then
reverseIndex = reverseIndex - 1
end
if reverseIndex % 4 >= 2 then
cValue = -cValue
end
value = value + cValue
end
return value
end
if not speaker then
speaker = chatServiceModule:AddSpeaker(name)
speaker:SetExtraData("NameColor", nameColors[getNameValue(name) % #nameColors + 1])
speaker:JoinChannel("All")
end
Lastly, we’ll have them say the message:
speaker:SayMessage("Hello!", "All")
If you’d like to have them send a message to just one particular speaker, use ChatSpeaker:SendMessage
instead.
Full code
local serverScriptService = game:GetService("ServerScriptService")
local chatServiceModule = require(serverScriptService:WaitForChild("ChatServiceRunner").ChatService)
local nameColors = {
Color3.fromRGB(253, 41, 67), -- BrickColor.new("Bright red").Color,
Color3.fromRGB(1, 162, 255), -- BrickColor.new("Bright blue").Color,
Color3.fromRGB(2, 184, 87), -- BrickColor.new("Earth green").Color,
BrickColor.new("Bright violet").Color,
BrickColor.new("Bright orange").Color,
BrickColor.new("Bright yellow").Color,
BrickColor.new("Light reddish violet").Color,
BrickColor.new("Brick yellow").Color,
}
local function getNameValue(name)
local value = 0
for index = 1, #name do
local cValue = name:sub(index, index):byte()
local reverseIndex = #name - index + 1
if #name % 2 == 1 then
reverseIndex = reverseIndex - 1
end
if reverseIndex % 4 >= 2 then
cValue = -cValue
end
value = value + cValue
end
return value
end
local speaker = chatServiceModule:GetSpeaker(name)
if not speaker then
speaker = chatServiceModule:AddSpeaker(name)
speaker:SetExtraData("NameColor", nameColors[getNameValue(name) % #nameColors + 1])
speaker:JoinChannel("All")
end
speaker:SayMessage("Hello!", "All")
Learn more here.