Actions
Overview
Actions is a module I’ve put together that allows you to bind a single callback to multiple events. This allows you to reduce your code and aims to make working with multiple devices easier.
Source
Example
local actions = require(script.Parent:WaitForChild'Actions')
local reset = actions:CreateAction("Reset", function ()
local player = game:GetService'Players'.LocalPlayer
local character = player and player.Character
local humanoid = character and character:FindFirstChildOfClass'Humanoid'
if humanoid then
humanoid.Health = 0
end
end)
local active = reset.Active
local toggle = actions:CreateAction("SetActive", function ()
active = not active
reset:SetActive(active)
end)
local userInputService = game:GetService'UserInputService'
reset:BindToInput({
UserInputState = Enum.UserInputState.Begin,
UserInputType = Enum.UserInputType.Keyboard,
KeyCode = Enum.KeyCode.R
})
toggle:Bind(userInputService.InputBegan, function (input)
return input.UserInputType == Enum.UserInputType.Keyboard
and input.KeyCode == Enum.KeyCode.T
end)