How to Change the Players Chat Name/Displayname

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Trying to set the players Chat Name to a Random Number (e.g. Player #34)

  1. What is the issue? Include screenshots / videos if possible!
    There is an Error with the Chat Service that makes no other player be able to chat.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried to search in the Forums but haven’t found anything

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

I tried this Script from another Forum by @HMgamingTheSecondary

-- TEST ON MY SPEAKER
local players = game:GetService('Players')
local chatService = require(script.Parent:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

local player = players:WaitForChild('Jen94943')
local speaker = nil
repeat
	speaker=chatService:GetSpeaker(player.Name)
	wait(0.1)
until speaker

speaker.Name='test'

I tried to change the script to make every player instead of one but doesn’t work. Even single-Player won’t work.

3 Likes

Here’s what you’ll need to do:

  1. Add a RemoteEvent inside of ReplicatedStorage (I left mine with the default name of “RemoteEvent”)
  2. Add a server Script inside of ServerScriptService, and write:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage.RemoteEvent

Players.PlayerAdded:Connect(function(player)
	remoteEvent:FireAllClients(player.UserId, math.random(1, 100))
end)

Players.PlayerRemoving:Connect(function(player)
	remoteEvent:FireAllClients(player.UserId, nil)
end)
  1. Add a LocalScript inside of StarterPlayerScripts, and write:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextChatService = game:GetService("TextChatService")

local remoteEvent = ReplicatedStorage.RemoteEvent

local nameStorage = {}

remoteEvent.OnClientEvent:Connect(function(userId, randomNumber)
	nameStorage[userId] = if randomNumber then `Player #{randomNumber}:` else nil
end)

TextChatService.OnIncomingMessage = function(message)
	if message.TextSource then
		if nameStorage[message.TextSource.UserId] then
			message.PrefixText = nameStorage[message.TextSource.UserId]
		else
			message.PrefixText = "Player #0:" -- This is an optional default value
		end
	end
end

As an example, the result will be formatted like so: Player #1: Hello!

1 Like

Is there any other way to use this but for Legacy Chat instead of Text Service?

It’s been a while since I used the legacy chat, plus it’s recommended to use TextChatService in new experiences since legacy chat has been depreciated

All right, but thanks I will use this script until I figure out some way for Legacy Chat, because my game does kinda look like Legacy Roblox

2 Likes

If I remember correctly, there are resources available that make TextChatService look similar to the legacy chat. I’ll try to look for them and will update this reply with the result :slight_smile::+1:


@Jen94943 This system made by AdvancedOpenGL is a modified version of the legacy chat’s scripts, and should be compatible with TextChatService:

1 Like

All right, Thank you for your help.

1 Like

Thank you, you’ve helped me a lot.

1 Like

Another bug started appearing, The Old Chat you sent me basically automatically sets the players name. I tried to fix this but didn’t work.

Unfortunately I keep getting the error:

GetCore: PlayerBlockedEvent has not been registered by the CoreScripts

whenever I attempt to test the original legacy chat. Are the scripts that I sent you still present when testing the Old Chat system?


@Jen94943 I managed to find a workaround to the error I was getting by manually copying and pasting the module into StarterPlayerScripts. Now that the original legacy chat is working for me, I’ll attempt to write a script that will change the names for you that uses it directly


@Jen94943 Unfortunately, I wasn’t able to find a solution to your problem. Hopefully someone else with more experience on the legacy chat’s scripts can help you achieve what you’re looking for, although I still recommend using TextChatService if possible

1 Like

To do it for the legacy chat, you could check when any speaker is added, it will happen when a player joins and their speaker is created. Then check if the speaker belongs to a player, if it does, change the .Name of the speaker:

local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)

local function speakerAdded(speakerName)
	local speaker = ChatService:GetSpeaker(speakerName)
	local player = speaker:GetPlayer()

	if not player then return end
	warn(speaker) -- this will print lot of information, all details of the speaker
	speaker.Name = "newName" -- set the new name in chat
end

ChatService.SpeakerAdded:Connect(speakerAdded) -- Listen when a speaker is added
-- Check current SpeakerList
for _, speaker in ipairs(ChatService:GetSpeakerList()) do
	speakerAdded(speaker)
end

Just one thing, after using this script on a server script and changing the speaker.Name, you could see some warnings in the ChatService module. Right now I’m leaving so I dont have time to check why that happens and Im rusty on using the legacy chat.
But I hope that helps you to find the track

3 Likes