Create fake chat messages from certain players?

Hi, I’m looking to create ‘fake’ messages from certain players to display in the chat menu:

image

Is there an API to already achieve this?

I’m aware of ChatMakeSystemMessage, however this only enables you to customise one colour. I’m looking for an API that allows you to manipulate the player’s name and player’s message, text and colour.

7 Likes

Try this out.

2 Likes

What you’d want to do is actually create a “speaker entity” using ChatService:AddSpeaker. Once done, you’d have access to the member functions of ChatSpeaker.

I haven’t personally experimented with ChatService, but I’d think it’d go something along the lines of:

local ChatSpeaker = ChatService:AddSpeaker("CustomPlayer")
ChatSpeaker:JoinChannel("All")

ChatSpeaker:SayMessage("Test")
5 Likes

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.

26 Likes

That’s perfect, thank you very much!

4 Likes