How would i make a toggle keybind using UserInputService?

Hi, so i’m trying to make a custom shiftlock controller, but since shiftlock is toggleable, i want to replicate that in my script.
Here is my code:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return false end
	if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
		Humanoid.CameraOffset =  Vector3.new(1.5, 0, 0)
		UserSettings().GameSettings.RotationType = Enum.RotationType.CameraRelative
	end
end)

This is a script inside of StarterPlayerScripts.
Help appreciated.

If i understand right you wanna change the keybind of the shiftlock right ?

No, i’m trying to make a custom shiftlock controller, not change the default keybind.

Have you tried using CAS? You can detect player keybinds much easier with it. User Input Service is pretty old and not recommended to use anymore.
I would also recommend creating a bool value like

ShiftLockEnabled = false

And checking for it on each shift press, then change the value to it’s opposite and give the camera the offset/reset it to normal