Relevant code (basically everything, left out services)
local timer = 0
local timerConnection
local ACTION_ZOOM = "Zoom"
local ACTION_TOGGLEFOCUS = "ChangeFocus"
local ACTION_TOGGLECAMERAMOVEMENT = "ToggleMoveCamera"
local ACTION_CAMERAMOVEMENT = "MoveCamera"
local ACTION_SELECT = "Selection"
local function BindTopDownActions(handleAction)
ContextActionService:BindAction(ACTION_ZOOM, handleAction, false, Enum.UserInputType.MouseWheel)
ContextActionService:BindAction(ACTION_SELECT, handleAction, false, Enum.UserInputType.MouseButton1)
ContextActionService:BindAction(ACTION_TOGGLECAMERAMOVEMENT, handleAction, false, Enum.UserInputType.MouseButton1)
end
local function UnbindTopDownActions()
ContextActionService:UnbindAction(ACTION_ZOOM)
print("Zoom Unbound")
ContextActionService:UnbindAction(ACTION_TOGGLECAMERAMOVEMENT)
print("Toggle Camera Unbound")
ContextActionService:UnbindAction(ACTION_CAMERAMOVEMENT)
print("Move Camera Unbound")
ContextActionService:UnbindAction(ACTION_SELECT)
print("Selection Unbound")
end
local function timerFunction(delta)
timer += delta
end
local function startTimer()
timer = 0
timerConnection = RunService.RenderStepped:Connect(timerFunction)
end
local function stopTimer()
if not timerConnection then return 0 end
timerConnection:Disconnect()
return timer
end
local function handleAction(actionName, inputState, inputObject)
print(actionName)
if actionName == ACTION_ZOOM then
if (inputObject.Position.Z == 1) then
CameraHandler.ZoomIn()
elseif (inputObject.Position.Z ~= 1) then
CameraHandler.ZoomOut()
end
elseif actionName == ACTION_TOGGLEFOCUS then
if inputState == Enum.UserInputState.End then
local newFocus = CameraHandler.ChangeFocus()
if newFocus == "Player" then
UnbindTopDownActions()
elseif newFocus == "TopDown" then
BindTopDownActions(handleAction)
end
end
elseif actionName == ACTION_TOGGLECAMERAMOVEMENT then
if inputState == Enum.UserInputState.Begin then
ContextActionService:BindAction(ACTION_CAMERAMOVEMENT, handleAction, false, Enum.UserInputType.MouseMovement)
CameraHandler.CurrentMousePosition = inputObject.Position
startTimer()
else
ContextActionService:UnbindAction(ACTION_CAMERAMOVEMENT)
local elapsed = stopTimer()
if elapsed <= 0.1 then
return Enum.ContextActionResult.Pass
end
end
elseif actionName == ACTION_CAMERAMOVEMENT then
CameraHandler.MovedTo(inputObject.Position)
elseif actionName == ACTION_SELECT then
if inputState == Enum.UserInputState.End then
CommandHandler.NewSelectionAtPoint(inputObject.Position)
end
end
end
ContextActionService:BindAction(ACTION_TOGGLEFOCUS, handleAction, true, Enum.KeyCode.C)
No, the CameraHandler does not have anything to do with keybinds, it doesn’t even have ContextActionService referenced.
When pressing C twice
Expected output:
ChangeFocus (x4)
Zoom Unbound
Toggle Camera Unbound
Move Camera Unbound
Selection Unbound
Actual output:
Please help I don’t know why is C triggering everything else