Renaming a player in the chat

Hi developers, I need some help implementing a thing for my admin script. We use the modern text chat and TextChatService and we implemented a command that allows staff to go undercover.
Unfortunately, this cover is easily blown due to the chat, as any chatting will show the mod’s name. We would therefore like to change the name of the moderator in the chat. Is this possible? How? Preferably via the server, but a client solutions works too.

Thank you!

1 Like

I haven’t worked a whole lot with the modern chat systems but I did make a chat tag system the other day utilising Roblox’s documentation they provide on it.

From what I understand a lot of the message editing and custom processing should (or possibly only can be) done on the client.

Unfortunately the only real modifications I’ve seen them allowing is for basic properties listed here.

I believe in this case you’d need to write your own custom chat, or copy the existing Roblox chat scripts and just modify them to your needs - this could also help you write the code on the server (I can’t actually remember if you can even do this anymore, the old system you could, sorry if this is inaccurate)

When implementing a custom chat, just be sure to adhere to Xbox rules if you support that platform: Xbox players aren’t allowed to see the chat under any circumstance. You can check whether the chat should be available via IsTenFootInterface

Hope this helps!

1 Like

You can make for example some stringvalue in the player with the current name for the player and try the following script

local TextChatService = game:GetService("TextChatService")

TextChatService.OnIncomingMessage = function(Text)
	local CallName = Text.PrefixText:sub(1,#Text.PrefixText-1)
	local Player = game.Players:FindFirstChild(CallName)
	if Player ~= nil then
		local CurrentNamePlayer = Player:FindFirstChild("CurrentName")
		Text.PrefixText = CurrentNamePlayer.Value..":"
	end
end

1 Like

You can’t modify the message itself. You’d need to use a TextChatMessageProperties instance and modify that.

local players = game:GetService("Players")
local tcs = game:GetService("TextChatService")

local function onMessage(message: TextChatMessage): TextChatMessageProperties
    local prop = Instance.new("TextChatMessageProperties")

    local player = if message.TextSource then
        players:GetPlayerByUserId(message.TextSource.UserId) else nil

    if not player then return prop end
    --checks if the player is admin should go here

    local coverName = --do stuff to get the undercover name

    prop.PrefixText = coverName..": "

    return prop
end

tcs.OnIncomingMessage = onMessage
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.