Using :Chat() to appear in the chat bar

Wanting to know if there’s anyway to use the Chat function to show chats in the bar? Atm it just does a bubble

Chat:Chat(Character.Head, v.Text, Enum.ChatColor.White)

Or is there a reason as to why there’s no way to do it? And is there a way for the chat to show up for all players then in the bubble? Kinda useless if it only shows for the client

2 Likes

Take a look at this:

Customizing In-Experience Text Chat | Documentation - Roblox Creator Hub

See if any of the methods available are of any use to you.

The methods I suggested are server side only by design. Use server side for this.

Alternatively, just post a system message designed to mimic a normal chat message when you call :Chat (once again, you will need to have some communication to the server for this).

2 Likes

To add onto that, here’s an example code which makes the player’s chat speaker say a message

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

local function Chat(plr, msg)
    local speaker = ChatService:GetSpeaker(plr.Name)
    if not speaker then
        return
    end
    speaker:SayMessage(msg, "All", {})
end

Chat(game.Players.NinjoOnline, "I was forced to say this")

(typed on a new phone with a bad autocorrect so forgive any typos)

4 Likes

There’s an event under the Chat service called Chatted. This is fired whenever :Chat() is called. Use this as a determinant to when to send messages to the chat bar.

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Chat = game:GetService("Chat")

-- CSR is not implicit, you need to wait for it
local ChatServiceRunner = ServerScriptService:WaitForChild("ChatServiceRunner")
local ChatService = require(ChatServiceRunner.ChatService)

Chat.Chatted:Connect(function (adornee, message)
    -- Assuming adornee is a character head
    local player = Players:GetPlayerFromCharacter(adornee.Parent)
    if player then
        local speaker = ChatService:GetSpeaker(player.Name)
        if speaker then
            speaker:SayMessage(message, "All", {})
        end
    end
end)

Tailoring it to non-players or for better control/checking is up to you. This will, however, log anything done from Chat.Chat (like your code sample above) and send it back to the Lua Chat System.


@Amiaa16 Why are you handling nil cases with a return?

if speaker then
    speaker:SayMessage(msg, "All", {})
end
1 Like
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Chat = game:GetService("Chat")

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

print(1)
Chat.Chatted:Connect(function(adornee, message)
	print(2)
    -- Assuming adornee is a character head
    local player = Players:GetPlayerFromCharacter(adornee.Parent)
    if player then
        local speaker = ChatService:GetSpeaker(player.Name)
        if speaker then
            speaker:SayMessage(message, 'All', {})
        end
    end
end)

Doesn’t even print 2 (prints 1) when I chat. Either using :Chat() or just manually typing a chat.

You sure about that, or did you not test properly? I inserted the exact code I gave you along with the prints and I fired off a test chat - it printed as expected, which is the opposite of what you reported.

Script in ServerScriptService with a line to check if my code worked:

game.Chat:Chat(workspace.colbert2677.Head, "test")

Expected prints of 1 and 2:
image

Client view:

Don’t run any of the code from the command bar if you are, they run on different VMs.

2 Likes

Does the :Chat() have to be in the server? I’m firing it from the client

EDIT Nvm that didn’t work either

local Chat = game:GetService('Chat')
local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')

local ChatServiceRunner = ServerScriptService:WaitForChild('ChatServiceRunner')
local ChatService = require(ChatServiceRunner.ChatService)
print(1)
Chat.Chatted:Connect(function(adornee, message)
    print(2)
    -- Assuming adornee is a character head
    local player = Players:GetPlayerFromCharacter(adornee.Parent)
    if player then
        local speaker = ChatService:GetSpeaker(player.Name)
        if speaker then
            speaker:SayMessage(message, 'All', {})
        end
    end
end)

Chat:Chat(workspace.NinjoOnline.Head, "test")

Chat bubble appears, but nothing shows in the chat bar, nor does print(2) print

EDIT
Full script

local Chat = game:GetService('Chat')
local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')

local ChatServiceRunner = ServerScriptService:WaitForChild('ChatServiceRunner')
local ChatService = require(ChatServiceRunner.ChatService)
print(1)
Chat.Chatted:Connect(function(adornee, message)
	print(2)
    -- Assuming adornee is a character head
    local player = Players:GetPlayerFromCharacter(adornee.Parent)
    if player then
        local speaker = ChatService:GetSpeaker(player.Name)
        if speaker then
            speaker:SayMessage(message, 'All', {})
        end
    end
end)
print(3)
workspace:WaitForChild("NinjoOnline")
Chat:Chat(workspace.NinjoOnline.Head, "test")
print(4)


Still doesn’t show in the bar

1 Like

Both of my scripts were ran from the server and worked fine as shown by the above repro. What is your current implementation setup and use case for involving the client?

1 Like