So i have some buttons in my game which can be activated by being clicked or by activating a hotkey. Problem is, the hotkey still opens the UI while the player is typing.
Is there a specific way to know when the player is typing so the hotkey doesn't activate while chatting?
[EDIT #1] I tried using ContextActionService, but the only events I can see for use are LocalToolEquipped and LocalToolUnequipped. How would I bind hotkeys to my UI buttons using ContextActionService?
UserInputService
is fine, there is a second parameter, a boolean, which is set to true if a player's input is being processed by the game, like inputting text into a text box, and most commonly, chatting.UIS.InputBegan:Connect(function(input, gpe) -- remember to define UserInputService if gpe then return end -- if they are chatting, stop the function -- your code here end)
ContextActionService
, you bind actions with a method, not an event. That method is called BindAction
. You can also create mobile buttons (they show only for mobile users!) with this method, and bind multiple keys, which is useful so you don't have to create multiple if
statements just to check if the key is one of the keys that can run the code.local function onKeyPress() -- code end CAS:BindAction( "Name", -- action name. put whatever onKeyPress, -- remember, don't add brackets, this is the function to bind false, -- want a mobile button? Set to true for one. Enum.KeyCode.E, -- just an example. you can bind multiple keys, the fourth arg is a tuple Enum.KeyCode.ButtonY -- example. keep using , and bind other keys if wanted )
It might have something to do with what method you are using to bind the buttons to the hotkeys. I have a similar system in my game except this problem doesn't seem to occur, are you using the Context Action Service to bind the keys? If not, I strongly suggest migrating to it.