Display Username in chat and not Display Name[TextChatService]

local PlayersService = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local chatInputBarConfiguration = TextChatService.ChatInputBarConfiguration

chatInputBarConfiguration.AutocompleteEnabled = false

local localPlayer = PlayersService.LocalPlayer

local function onMessageReceived(textChatMessage)
    local textSource = textChatMessage.FromSpeakerName
    local chattingPlayer = PlayersService:GetPlayerByUserId(textSource)

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

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

Error: FromSpeakerName is not a valid member of TextChatMessage “Instance”
ChatVersion : TextChatService
this script should display Username in chat and not Display Name

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