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