Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I properly 'keybind' this script?

I've been using 'keybinds' in local scripts and they seem to work fine. The only issue is that: these 'keybinds' activate even when typing in the chat. I'm using UserInputService. Perhaps I should be using something else or perhaps I've been taking the wrong approach? Here is the script.

function KeyDown(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.F and InventoryOpened == false then
		(Insignificant stuff)
	end
end




game:GetService("UserInputService").InputBegan:connect(KeyDown)

I appreciate the help.

2 comments

0

What do you mean they activate even when typing in the chat?

0

Your title is a bit misleading, your script checks key input and does not keybind. For Keybinding you need to use the "ContextActionService" to bind an action to an input. An example can be found if you run studio as a test the navigate to starterPlayer->StarterPlayerScripts->ControlScript->MasterControl->KeyboardMovement

1 answer

✓ Accepted answer

GameProcessedEvent
Did you see that?

The gameProcessedEvent argument of the UIS events tell you whether the input was directed to the game or whether it was intercepted by something such as a TextBox. Check that to see if the user is typing, and then return out of the function if they are.

This discussion is preserved as it was. New answers, comments, and votes are closed.