So in some games when a player is typing a little bubble chat appears at the top of the head.
And im searching how to replicate this.
The best i tried is searching on YT, API reference, and it says nothing at all.
This should work it detects the moment the player selected the text field. Use this in a local script of course.
local userInputService = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local Chat = plr.PlayerGui:WaitForChild("Chat")
local ChatBox = Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame:WaitForChild("ChatBar")
userInputService.InputBegan:Connect(function()
local focus = ChatBox:IsFocused()
if focus == true then
--The code you want to run!
end
end)
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local function onInputBegan(input, gameProcessedEvent)
if gameProcessedEvent then
return
end
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Unknown and input.UserInputState == Enum.UserInputState.Begin then
local player = Players:GetPlayerFromCharacter(input.UserInputType)
if player then
print(player.Name .. " is typing")
end
end
end
UserInputService.InputBegan:Connect(onInputBegan)
there are also simple ways, I wouldn’t call this complex.
Don’t worry, the script I sent a few minutes ago probably works unless I forgot something it checks both if the player is pressing keys and if the chatbox is selected on the client side.
Is there a way to pull this same similar method with the new TextChatService?
Edit: I ask this because, for any unaware, the new TextChatService stores the new chat UI in CoreGui, which is permission locked and unable to be accessed by scripts. LegacyChatService stores the chat UI in PlayerGui, which isn’t permission locked.
Hi Jeebus, Yeah you can do that two by looking if the player is focused on a chatbox. Here is a sample script I’ve just made that checks if the player is focused on a chatbox and if they pressed F of course you could just leave that out depending on what you want to do with it, Hope it helps!
local userInputService = game:GetService("UserInputService")
userInputService.InputBegan:Connect(function(InputKey)
local TextBox = userInputService:GetFocusedTextBox() -- gets the focused chatbox
if not TextBox then -- if no chat box is focused it'll check if the player pressed f and then it prints "F pressed"
if InputKey.KeyCode == Enum.KeyCode.F then -- you can leave this out depending on what you want to do
print("F pressed")
end
else
print("FocusedOnChatBox")
end
end)