Normally if you hold a key, and then press Escape, and then let go, the “Cancel” state fires and you can handle your code there, however the same does not apply for Mouse inputs.
In this video, I have the shooting function binded to MouseButton1, and as you can see the Cancel state does not fire.
My code:
function ActionBehaviors.Charge(actionData, inputState, actionName)
local startState = actionData.States.Start
local finishState = actionData.States.Finish
local layer = GetLayer(startState)
local current = StateClient:GetState(layer)
print(inputState)
if inputState == Enum.UserInputState.Begin then
if StateResolver.CanOverride(current, startState) then
StateClient:PredictState(startState)
PlayAnim(humanoid, actionData, "Start")
TriggerActionModule(actionName, "Start")
end
elseif inputState == Enum.UserInputState.End or inputState == Enum.UserInputState.Cancel then
if current == startState then
StopAnim(humanoid, actionData, "Start")
StateClient:PredictState(finishState)
PlayAnim(humanoid, actionData, "Finish")
TriggerActionModule(actionName, "Finish")
end
end
end