With the new chat system in place, I was wondering if you could detect what the player is typing before it is sent. In the LegacyChatService you could get the chat from the PlayersGui and see when the chatbox is being changed. Is there an alternative to this using the new chat system?
With the new chat system you cannot detect what a player is typing before they send it due to security and privacy reasons, although you can detect what they send by using this script:
local TCS = game:GetService("TextChatService")
TCS.OnIncomingMessage = function(msg)
print(msg.Text)
end
Keep in mind this will need to be in a local script within the player
Would creating a custom chat system as a replica to the new one work?
Would it be possible to get what they are typing from keystrokes?, like check the letters after they press slash
No, this is not possible. You can only detect their sent and received messages, not their messages in progress.
Contrary to what others said there’s a trick you can use to determine if the user is typing in the chat window’s text box.
You can use UserInputService for this and rely on the fact that with the new TextChatService you cannot access the chat bar instance because normal scripts lack permission to access CoreGui.
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
uis.InputBegan:Connect(function(input, gameProcessed)
-- Check if the input was processed by the engine for UI purposes
if gameProcessed then
local textBox
local success = pcall(function()
textBox = uis:GetFocusedTextBox()
local _ = textBox.Name -- Trigger permission error
end)
-- success will be false when using the new TextChatService because its chat bar is part of CoreGui which normal scripts can't access because they lack permission
local isTypingMsg = not success
-- If the pcall succeds the player focused another text box which is not the new TextChatService's one
if success then
-- Check if the focused text box is the legacy chat bar
local legacyChatBar = nil
local legacyChatGui = playerGui:FindFirstChild("Chat")
-- legacyChatGui is nil when the game uses the new TextChatService
if legacyChatGui then
legacyChatBar = legacyChatGui:FindFirstChild("ChatBar", true)
end
isTypingMsg = textBox == legacyChatBar
end
if isTypingMsg then
print("Player is typing msg")
-- Here you can apply your code to know what the player is typing by reading from the input argument
end
end
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.