Roblox ActionBinds

Roblox ActionBinds is a module that will allow you to easily create actions that can be controlled my key presses and other means.

You can see the documentation on how to install and use it here:
SheepWizard/Roblox-ActionBinds (github.com)

Here is a quick demonstration of how to use it:

local ActionBinds = require(script.Parent:WaitForChild("ActionBinds"))

-- Create a action called 'sprint' whos events will be controlled by left or right shift.
ActionBinds.newAction("sprint", {Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift}, false)
ActionBinds.newAction("reload", {Enum.KeyCode.R}, false)

-- When 'R' is pressed this event will run.
ActionBinds.OnActionKeyPressed("reload", function(keycode)
	print("Reload button pressed with key " .. tostring(keycode))
end)
-- When left or right shift is pressed this event will run, disabling the reload event.
ActionBinds.OnActionKeyPressed("sprint", function(keycode)
	print("Start sprinting.")
	ActionBinds.disable("reload") -- Disable reload action
end)	
-- When left or right shift is released this even will run, enabling the reload event
ActionBinds.OnActionKeyReleased("sprint", function(keycode)
	print("Stop sprinting.")
	ActionBinds.enable("reload") -- Enable reload action
end)

I know similar modules exist but I wanted to try make one that was very quick and easy to use with minimal amount of code. I also added some basic support GUI button and the ability to run action events independently from there assigned keys.

If you have any questions or suggestions feel free too ask.

5 Likes

Why should we use this module over ContextActionService?

1 Like

Yes, as @iiLevelMaker said, if this doesn’t use the ContextActionService, you are supporting not adding mobile support. Also, ContextActionService is basically just this but with built in buttons for mobile support.

1 Like

That is true that it does a lot of similar things to ContextActionService, here are a few things I think this module does that differentiates itself from ContextActionService :

Easier to disable, enable actions. This can be done using:

ActionBinds.enable
ActionBinds.disable

Compared to ContextActionService where you can unbind a action but to rebind you have to enter all the parameters again.

Can bind actions to any GUI button, compared to ContextActionService which is only for mobile buttons which have a limited appearence.

Can check is a action is currently active which you can not do with ContextActionService .

Can independently run a actions events in your code without the need for any buttons to be pressed.

ActionBinds.runActionEvents

Easier to assign new keys to a action with

ActionBinds.getKeys
ActionBinds.changeKeys

More control over inputs being game processed or not.

Im sure there are also lots of things ContextActionService does better then this but from my experience I have always found ContextActionService annoying to use so I made this.

Does this allow built in mobile support like ContextActionService, though?

No it does not specifically have mobile support but you can use it to make clickable button for mobile.

Like I said above it does a lot of thing similar to ContextActionService and also a few things different, so pick what ever fits the needs of you game best. For the game I was making ContextActionService did not offer all the features I wanted so I made this instead.