Introducing InputActionService!
InputActionService is a simple module that is dedicated to provide an easy way for developers to create and manage input actions via scripts. By coding with this module, InputActions-related instances are no longer needed to be placed in Studio in advance. Instead, you manage them all in scripts!
Installation
Install it here: Roblox Marketplace
Guide
Here, we’ll be writing a simple input listener for sprinting.
local Players = game.Players
local Player = Players.LocalPlayer
local IAS = require(path.to.InputActionService)
-->> Parameters: Name?, Parent?, Priority?, Sink?
-->> Returns: Context, InputContext
local Context, Inst = IAS("ActionContext", Player:WaitForChild("StarterGui"))
-->> Parameters: Name?, InputActionType?
-->> Returns: Action, InputAction
local SprintAction, Inst = Context:CreateAction("Sprint", Enum.InputActionType.Bool)
-->> Parameters: Name?, Properties: {[PropertyName]: Value?}?
-->> Returns: InputBinding
local Inst = SprintAction:CreateBinding("SprintBind",
-->> List of available properties are shown on scripting assist/hint.
{
KeyCode = Enum.KeyCode.LeftShift,
UIButton = Instance.new("ImageButton") -->> Input your button instance here.
}
)
SprintAction.Pressed:Connect(function()
-->> Write your logic here
end)
SprintAction.Released:Connect(function()
-->> Write your logic here
end)
SprintAction.StateChanged:Connect(function()
-->> Write your logic here
end)
-->> THESE ARE UNRELATED TO THE EXAMPLE, BUT ARE PART OF THE MODULE!
SprintAction:FireState(true) -->> Force setting the state to true.
local state = SprintAction:GetState() -->> Returns the state.
Rating the module would help a lot!
What ya think
- Awesome module!
- Pretty solid.
- Not really that good. (Please leave suggestions!)
0
voters
Consider donating! It would help a lot.
Donate via this Roblox place.
Credits
@AlexanderLindholt for the Signal+ module.