You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I need to display all players display names in chat
What is the issue?
This feature is integrated already as a default for games, but for this one somehow it got disabled and for the life of me i cannot figure out how to fix it. It shows the player’s actual username in chat, but i need the display name.
What solutions have you tried so far?
After searching the devforum i see stuff on how to disable displaynames, but not how to enable them (yes i’ve tried to reverse this process to no avail). There is fix i can see that will help me re-enable these display names that used to be default in the new TextChatService as shown here.
I tried to use this code, and it works except for the part where it doesn’t display the client it runs on’s display name, just everyone elses.
I tried this code already to fix it, maybe i was on the right track??
-- this is on the client
local PlayersService = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local localPlayer = game.Players.LocalPlayer
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.Name, chattingPlayer.DisplayName))
end
end
local function onSendingMessage(textChatMessage: TextChatMessage)
textChatMessage.PrefixText = (textChatMessage.PrefixText:gsub(localPlayer.Name, localPlayer.DisplayName))
end
-- connect to events
TextChatService.MessageReceived:Connect(onMessageReceived)
TextChatService.SendingMessage:Connect(onSendingMessage)
Do you have any other code that interfaces with MessageReceived and SendingMessage?
Seems like some other script such as the ChatColours could be changing the prefix
--!strict
----------------- ╭──────────╮ -----------------
----------------- │ Services │ -----------------
----------------- ╰──────────╯ -----------------
local PLAYERS = game:GetService("Players")
local TEXT_CHAT_SERVICE = game:GetService("TextChatService")
--============================================--
---------------- ╭───────────╮ -----------------
---------------- │ Functions │ -----------------
---------------- ╰───────────╯ -----------------
function OnIncomingMsg(msg: TextChatMessage)
local player = PLAYERS:GetPlayerByUserId(msg.TextSource.UserId)
local minutes = player.leaderstats.Minutes.Value
local properties = Instance.new("TextChatMessageProperties")
properties.PrefixText =
if minutes < 5000
then `<font color="#FFF"><b>{msg.TextSource.Name}:</b></font>`
else `<font color="rgb(247, 38, 59)"><b>{msg.TextSource.Name}:</b></font>`
return properties
end
-------------- ╭────────────────╮ --------------
-------------- │ Initialisation │ --------------
-------------- ╰────────────────╯ --------------
TEXT_CHAT_SERVICE.OnIncomingMessage = OnIncomingMsg
This script throws an error about textsource being nil. Disabling it fixes chat display names. I also cannot figure out what is wrong with this one, this was done by someone else. Any help would be appreciated! thanks for pointing that out to me!
i do not! its just the random color stuff this guy did, it was done without my knowledge. and the client display name script which basically works except for the local player