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

Any way to filter out chat for a keyboard command?

Asked by 6 years ago

Self explanatory really, I have a UserInputService that has a gui pop up when a key is pressed. This is annoying when a player is chatting. Any way around this?

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
6 years ago

All you need to do in your code is check whether the TextBox for the chat is currently selected or not, and run your code accordingly. To accomplish this, we simply define a variable for the TextBox, and in the UserInputService event, do something like this:

local uis = game:GetService("UserInputService")

local player = game.Players.LocalPlayer

local chatBox = player.PlayerGui:WaitForChild("Chat"):FindFirstChild("ChatBar", true)

uis.InputBegan:connect(function(inputObject)
    if not chatBox:IsFocused() then
        print("This code prints this message!") --Your code here
    end
end)

I believe that this code should work for your purposes. If you have any further questions I am happy to answer them, just let me know. Hope this helps :)

1
Works great! I could not find this property to check if the user is chatting, thank you! TiredMelon 405 — 6y
0
No problem, glad I could help! dyler3 1510 — 6y
Ad

Answer this question