How can I remove display names in TextChatService?

I have tried this code,

local TT = 	game:GetService("TextChatService")
local Bar = TT.ChatInputBarConfiguration
local Window = TT.ChatWindowConfiguration
local RS = game:GetService("RunService")

local function onFocused()
	Bar.BackgroundColor3 = Color3.fromRGB(255,255,255)
	Bar.TextColor3 = Color3.fromRGB(25, 27, 29)
	Bar.TextStrokeColor3 = Color3.fromRGB(255, 255, 255)
end

local function FocusLost()
	Bar.BackgroundColor3 = Color3.fromRGB(25, 27, 29)
	Bar.TextColor3 = Color3.fromRGB(255, 255, 255)
	Bar.TextStrokeColor3 = Color3.fromRGB(0,0,0)
end

local localplayer = game.Players.LocalPlayer
local PlayersService = game:GetService("Players")

local function onMessageReceived(textChatMessage: TextChatMessage)
	local textSource = textChatMessage.TextSource
	local chattingPlayer = if textSource
		then PlayersService:GetPlayerByUserId(textSource.UserId)
		else nil

	if chattingPlayer then
		textChatMessage.PrefixText = (textChatMessage.PrefixText:gsub(chattingPlayer.DisplayName, chattingPlayer.Name))
	end
end
local function onSendingMessage(textChatMessage: TextChatMessage)
	textChatMessage.PrefixText = (textChatMessage.PrefixText:gsub(localplayer.DisplayName, localplayer.Name))
end

Bar:GetPropertyChangedSignal("IsFocused"):Connect(onFocused)

TT.MessageReceived:Connect(onMessageReceived)
TT.SendingMessage:Connect(onSendingMessage)

RS.Heartbeat:Connect(function()
	if not Bar.IsFocused then
		FocusLost()
	end
end)

Onsendingmessage and onrecieving functions just doesn’t work.

You need to be using TextChatService.OnIncomingMessage

function textChatService.OnIncomingMessage(textChatMessage: TextChatService)
    local source = textChatMessage.TextSource

    if not source then return end
    
    local player = players:GetPlayerByUserId(source.UserId)    

    local textChatMessageProperties = Instance.new('TextChatMessageProperties')
    textChatMessageProperties.PrefixText = textChatMessage.PrefixText:gsub(player.DisplayName, player.Name)
    
    return textChatMessageProperties
end
1 Like

Returns error;

OnIncomingMessage is a callback member of textchatservice; you can only set callback value, get is not avaliable

Can you show how you implemented it

local TT = 	game:GetService("TextChatService")
local Bar = TT.ChatInputBarConfiguration
local Window = TT.ChatWindowConfiguration
local RS = game:GetService("RunService")

local function onFocused()
	Bar.BackgroundColor3 = Color3.fromRGB(255,255,255)
	Bar.TextColor3 = Color3.fromRGB(25, 27, 29)
	Bar.TextStrokeColor3 = Color3.fromRGB(255, 255, 255)
end

local function FocusLost()
	Bar.BackgroundColor3 = Color3.fromRGB(25, 27, 29)
	Bar.TextColor3 = Color3.fromRGB(255, 255, 255)
	Bar.TextStrokeColor3 = Color3.fromRGB(0,0,0)
end

local localplayer = game.Players.LocalPlayer
local PlayersService = game:GetService("Players")

local function OnIncomingMessage(textChatMessage: TextChatService)
	local source = textChatMessage.TextSource

	if not source then return end

	local player = PlayersService:GetPlayerByUserId(source.UserId)    

	local textChatMessageProperties = Instance.new('TextChatMessageProperties')
	textChatMessageProperties.PrefixText = textChatMessage.PrefixText:gsub(player.DisplayName, player.Name)

	return textChatMessageProperties
end

Bar:GetPropertyChangedSignal("IsFocused"):Connect(onFocused)

TT.OnIncomingMessage(OnIncomingMessage)

RS.Heartbeat:Connect(function()
	if not Bar.IsFocused then
		FocusLost()
	end
end)

Should be TT.OnIncomingMessage = OnIncomingMessage

Returns error;

attempt to index nil with 'TextSource'
Line 22 function OnInComingMessage
Line 36

You didn’t add any parentheses after OnIncomingMessage right? If not, add a guard clause before the local source to check if textChatmessage isn’t nil

what do you mean by a guard clause, apologies but I have never heard such a reference?

if not textChatMessage then return end

No errors anymore, although it still displays the players display name and not his user

Can you show your implementation now?

local TT = 	game:GetService("TextChatService")
local Bar = TT.ChatInputBarConfiguration
local Window = TT.ChatWindowConfiguration
local RS = game:GetService("RunService")

local function onFocused()
	Bar.BackgroundColor3 = Color3.fromRGB(255,255,255)
	Bar.TextColor3 = Color3.fromRGB(25, 27, 29)
	Bar.TextStrokeColor3 = Color3.fromRGB(255, 255, 255)
end

local function FocusLost()
	Bar.BackgroundColor3 = Color3.fromRGB(25, 27, 29)
	Bar.TextColor3 = Color3.fromRGB(255, 255, 255)
	Bar.TextStrokeColor3 = Color3.fromRGB(0,0,0)
end

local localplayer = game.Players.LocalPlayer
local PlayersService = game:GetService("Players")

local function OnIncomingMessage(textChatMessage: TextChatService)
	if not textChatMessage then return end
	local source = textChatMessage.TextSource

	if not source then return end

	local player = PlayersService:GetPlayerByUserId(source.UserId)    

	local textChatMessageProperties = Instance.new('TextChatMessageProperties')
	textChatMessageProperties.PrefixText = textChatMessage.PrefixText:gsub(player.DisplayName, player.Name)

	return textChatMessageProperties
end

Bar:GetPropertyChangedSignal("IsFocused"):Connect(onFocused)

TT.OnIncomingMessage = OnIncomingMessage()

RS.Heartbeat:Connect(function()
	if not Bar.IsFocused then
		FocusLost()
	end
end)

You need to remove the parentheses here

1 Like

Absolutely love you, thanks for the solution. I had similar posts to this and no one would give me a valid answer

1 Like

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