I’m trying to make a script to change every player’s character torso (R6 game) color to their chat name color.
I found out that I can use the Lua Chat System API to do this. Apparently, it’s supposed to be done with ChatSpeaker:GetExtraData(“NameColor”).
Below is the code I’ve tried so far. It doesn’t work, even though there are no errors. The ChatService.SpeakerAdded event never fires and ChatService:GetChannelList() returns an empty array. I can’t figure out why this is happening. Am I not using the ChatService module correctly? I wanna avoid forking the Chat scripts. Please help.
PS I didn’t use Players.PlayerAdded, because I don’t know if a player’s ChatSpeaker is ready by the time the event fires. The only info I’ve found is that “Each Player
connected to the game automatically has an associated ChatSpeaker.”.
local Players = game:GetService("Players")
local Chat = game:GetService("Chat")
local ChatServiceRunner = Chat:WaitForChild("ChatServiceRunner")
local ChatService = require(ChatServiceRunner:WaitForChild("ChatService"))
local function onSpeakerAdded(SpeakerName)
local Player = Players[SpeakerName]
if Player == nil then return end
local Speaker = ChatService:GetSpeaker(SpeakerName)
local NameColor = Speaker:GetExtraData("NameColor")
local function onCharacterAdded(Character)
local Torso = Character.Torso
Torso.Color = NameColor
end
Player.CharacterAdded:Connect(onCharacterAdded)
local Character = Player.Character
if Character == nil then return end
onCharacterAdded(Character)
end
ChatService.SpeakerAdded:Connect(onSpeakerAdded)
for _, ChannelName in ipairs(ChatService:GetChannelList()) do
local Channel = ChatService:GetChannel(ChannelName)
for _, SpeakerName in ipairs(Channel:GetSpeakerList()) do
onSpeakerAdded(SpeakerName)
end
end