Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I test if a player is typing in chat?

Asked by
baxzzi 42
5 years ago

I want to figure out if there is a way so that you can test if a player is typing in chat but did not press enter yet. Any ideas?

I already found another question on this site but, that's from 3 years ago and it doesn't really work. Here it is

game:GetService('UserInputService').TextBoxFocused:connect(function(TextBox)
    local succ = pcall(function() TextBox:GetFullName() end)
    if not succ then print('User is typing.') end
end)

game:GetService('UserInputService').TextBoxFocusReleased:connect(function(TextBox)
    local succ = pcall(function() TextBox:GetFullName() end)
    if not succ then print('User quit typing.') end
end)

(Credit goes to M39a9am3R, I'm just wondering if someone can figure out to make this work, I have no idea how to possibly make this script work.)

2 answers

Log in to vote
5
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Use UserInputServices GameProcessed parameter

UserInputService.InputBegan:Connect(function(InoutObject, GameProcessed)
   if (InputObject.UserInputType = Enum.UserInputType.KeyBoard) then
      if (GameProcessed) then --// Otherwise known as 'IsTyping'
         print("Is Typing!")
      end
   end
end)

Or, you could just say what's below, yet I highly recommend what's above

TextBox.Focused:Connect(function()
   print("Is Typing!")
end)

TextBox.FocusLost:Connect(function(Return) --// Parameter that you can restric to if pressed return
   print("Quit typing")
end)

I forgot to mention that GameProcessed binds to anything requirng interaction, Eg. Jumping, GuiButtons, etc, so I added a UserInputType check that narrows things down a bit. (Shout to Incap)

Hope this helps!

0
Okay, so I'm sure this works however, I'm struggling to find out where to place this into in the game? Also, whenever I put this in the game, "UserInputService" appears with an orange underline. baxzzi 42 — 5y
0
I’ve never experienced the description you’re giving about UserInputService having an orange underline Ziffixture 6913 — 5y
0
But I believe it should be a LocalScript inside ‘StarterPlayerScripts’, you may require Client-to-Server communication depending on what you’re attempting to make, therefore you might want to read up on RemoteEvents Ziffixture 6913 — 5y
0
Highly recommend you put in the variables too sir in case new scripters don't read errors or know about services. Also please check for any errors before posting solutions, Posting solutions with syntax errors isn't really helping sir, LINE 1 parameter 1 name is different to the name used in LINE 2, LINE 2 used = in a comparison statement where == should have been used. iiscrx 0 — 1y
Ad
Log in to vote
2
Answered by 5 years ago

Extension to Feahren's answer

Feahren's solution works quite well, but I felt like something was missing, that I felt was too big to fit in a comment.

Game Processed Event isn't only true when typing

Game Processed Event is true when the UI was interacted with in general. Clicking on a GUI button will fire InputBegan, and also cause game processed event to be true. You should also be checking if the user input type is Keyboard before doing anything else.

UserInputService.InputBegan:Connect(function(input, gpe)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if gpe then
            -- # extra sure that it wasn't button clicking
        end
    end
end)

Do not forget to accept Feahren's answer if this helps.

0
Thanks Incapaxian, I'll be sure to fix that, I forgot to mention thet GP also binds to jumping etc;) Ziffixture 6913 — 5y

Answer this question