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?
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
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