I want make a contextactionService with more than one input:
What have I tried so far?
I did but its not that good “S” and “Q” can be used for the same input to print(“hey”)
my Script:
local function handleAction(actionName, inputState, inputObject)
if actionName == Properties.Action and inputState == Enum.UserInputState.Begin
and Properties.pressedQ == false then
Properties.pressedQ = true
end
if actionName == Properties.Action and inputState == Enum.UserInputState.Begin then
print("hey")
end
end
CAS:BindAction(Properties.Action, handleAction, true, Enum.KeyCode.Q, Enum.KeyCode.S)
I’m still a little confused but I think I understand what you’re trying to say.
local function handleAction(actionName, inputState, inputObject)
local pressedQ = (inputObject.KeyCode == Enum.KeyCode.Q)
local pressedS = (inputObject.KeyCode == Enum.KeyCode.S)
if actionName == Properties.Action and inputState == Enum.UserInputState.Begin then
if pressedQ then -- check if they pressed the Q button
print("pressed 'Q'")
else -- otherwise they pressed S
print("pressed 'S'")
end
print('hey')
return Enum.ContextActionResult.Pass -- passes the input
else
return Enum.ContextActionResult.Sink -- sinks the input
end
end
CAS:BindAction(Properties.Action, handleAction, true, Enum.KeyCode.Q, Enum.KeyCode.S)
This prints the name of all of the keycodes that are pressed. If you want boolean variables for different keys, you’d have to modify the script I previously sent (just follow what I did).
local function handleAction(actionName, inputState, inputObject)
if actionName == Properties.Action and inputState == Enum.UserInputState.Begin then
print(string.format("pressed '%s'", inputObject.KeyCode.Name)) -- prints the name of the keycode that was pressed
print('hey')
return Enum.ContextActionResult.Pass -- passes the input
else
return Enum.ContextActionResult.Sink -- sinks the input
end
end
CAS:BindAction(Properties.Action, handleAction, true, Enum.KeyCode.Q, Enum.KeyCode.S)