All three of these have an issue. They trigger not only when I press them down, but also when I lift them up. How can I fix this?
BONUS
When I bound the MB2, it now no longer works with moving the camera. How can I have it bound to my use, but also camera movement, at the same time?
An answer to the first question:
The function is triggered any time a change is made to the input (if that makes sense).
There are many different states, see this for more info:
If you only want it firing when the button is pressed down, then you can check in the handler function like this:
if inputState == Enum.UserInputState.Begin then
--Do stuff here
end
An answer to question number two:
The default roblox controller scripts use ContextActionService to bind the inputs, with CAS, you can only have one thing bound to each key at a time, so by binding to MB2, you are overwriting the default controller script’s bind, and it therefore does not detect an input from that anymore.
For number 1,
Right, but I can’t do that whole if statement thing inside the arguments for bounding keys with CAS right? Because it just asks for the keycode?
For number 2,
So that’s why the problem is occurring, but how can I fix this?
local contextAction = game:GetService("ContextActionService")
local function kickMove(actionName, inputState, inputObject)
if actionName == "Kick" then --This is a given.
if inputState.UserInputState == Enum.UserInputState.Begin then --This checks the state of the input (began, changed, ended).
if inputObject.KeyCode == Enum.KeyCode.E then --This checks the input object (the input which triggered the action).
--Perform "kick" action here.
end
end
end
end
contextAction:BindAction("Kick", kickMove, false, Enum.KeyCode.E)
Here’s what you should be doing, using your “kick” action as an example.