Displaying chat bubbles as TextLabels in GUI

:wave: Hey Developers!

I am working on a new project, and I was wondering if it’s possible to display the chat bubbles that a user says as TextLabels in a ScreenGUI for everyone else to see.

To give some more details. when a specified users chats, their message gets displayed a TextLabel on the top of the screen temporarily so as all other players in the server can read them (if they are far away for example).

If this is indeed possible,
How would I achieve something like this?

Thanks in advance!

You can use the TextChatService.OnIncomingMessage callback for the new TextChatService.

--LocalScript
local tcs = game:GetService("TextChatService")

local function onMessage(message:TextChatMessage)
	
    if message.TextSource then
        local player = playersService:GetPlayerByUserId(message.TextSource.UserId)
		local name = player.Name
        TextLabel.Text = "@"..name.." chatted message: "..message.Text
    end
end

tcs.OnIncomingMessage = onMessage

This works really well, thanks! :heart_hands:

Do you know if it’s possible to make this script pickup and use messages sent by specified users only? Eg: Player1 and Player2 two are chatting, but only Player1’s messages are picked up and inserted in the TextLabel.

I’m not too sure if this would work, but you could try this;

local tcs = game:GetService("TextChatService")
local playerone = 1234567 -- set to player one id

local function onMessage(message:TextChatMessage)
	
    if message.TextSource and playersService:GetPlayerByUserId(message.TextSource.UserId).UserId == playerone then
        local player = playersService:GetPlayerByUserId(message.TextSource.UserId)
		local name = player.Name
        TextLabel.Text = "@"..name.." chatted message: "..message.Text
    end
end

tcs.OnIncomingMessage = onMessage
1 Like

Works perfectly, thank you! The script does exactly what needed. :+1:

1 Like

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