UserInputEvents: Easily create bindableEvents that correspond to user inputs!

Hello all! I made a quick little script to help me out with handling player inputs.

I’ve always been annoyed with how much boilerplate code goes into handling player inputs with UserInputService, so I created a ModuleScript that allows me to create bindable events linked to player inputs that I can then listen for in order to clean up my code.

You can read all about how to use it and copy the code on my github repo.

Current limitations:

  • Keyboard only
  • Uses InputBegan only
  • Cannot link multiple inputs to one event (I’ll be adding support for these features as I need them. Feel free to submit a PR though!)

Hope someone finds it useful! :wave:

2 Likes

I’m a bit confused about this. You say your module uses less boilerplate, but it actually doesn’t.

(Yours - 6 lines)

local module = require(path.to.module)
module.init()
local remote = module.CreateBind(Enum.KeyCode.E)
remote.Event:Connect(function(...)
    print(...)
end)

(Roblox - 4 lines)

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
    print(input)
end)

You also don’t fire the event with the gameProcessed parameter, limiting functionality.

(Also - name the GitHub file with a .lua at the end to make it highlight)

3 Likes

Why would I use BindableEvents, if I can just do this

game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)

end)

Is there any reason why I should use this module?

4 Likes

I often find myself having a function connected to UserInputService.InputBegan that makes sense of the input and invokes the correct function. This gets messy when I have over 12 binds, or have to do it in multiple scripts. Using BindableEvents in this way allows me to clean up some of that mess.

To be fair this module isn’t really helpful.

InputBegan does the job just right and also bindable events have a delay so you probably should think of something else to fire events