With TextChatService.OnIncomingMessage, is there a way to get the player sending the message?

Hello All,
I’m making a language game in my freetime where you choose a race, and you have to discover parts of other races’ languages in order to communicate with other players.

It’s working so far, But I’ve hit a roadblock with the OnIncomingMessage event. Is there any way to get the player instance within this event?

For example, if the player “John Doe” says something in chat, is there a way to get John Does player instance within the OnIncomingMessage event?

This is all the code I currently have inside a Local script for the OnIncomingMessage event:

local TX = game:GetService("TextChatService")
local RGC = TX:WaitForChild("TextChannels"):WaitForChild("RBXGeneral")
local REP = game:GetService("ReplicatedStorage")

local function updateChat(msg)
	local properties = Instance.new("TextChatMessageProperties")
	
	local newMsg = REP.Events.CheckMsg:InvokeServer(msg.Text)
	properties.Text = newMsg
	
	return properties
end

TX.OnIncomingMessage = updateChat

yes, you can!

local players = game:GetService("Players")

local function updateChat(msg: TextChatMessage): TextChatMessageProperties
    --some code here

    --TextSource references the source of the message.
    --If a player sent it, the text source has a UserId field with the player's UserId
    local player = message.TextSource and players:GetPlayerByUserId(message.TextSource.UserId)
    if (not player) then return end

    --other code here
end

game:GetService(“Players”):GetPlayerByUserId(Message.TextSource.UserId)

lol i didn’t saw that :joy: :joy: :joy: :joy: :joy: :joy: :joy:

TextSource | Documentation - Roblox Creator Hub

 -- connect to chat message here
 game.Players:GetPlayerByUserId(Message.TextSource.UserId)
 -- run your code here

Thank you!
I completely forgot to close this topic after I saw your solution lol.

1 Like

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