Hi, I've been using UserInputService for a long time with no problems, only my script doesn't want to work now. My script's location is in StarterPlayer.StarterPlayerScripts, also it's a local script.
local Players = game:GetService("Players") local Player = Players.LocalPlayer local UserInputService = game:GetService("UserInputService") function onInputBegan(input, gameProcessed) if gameProcessed then print(gameProcessed) return end if input == Enum.KeyCode.V then print(input) if Player.CameraMode == Enum.CameraMode.Classic then Player.CameraMode = Enum.CameraMode.LockFirstPerson else Player.CameraMode = Enum.CameraMode.Classic end end end UserInputService.InputBegan:Connect(onInputBegan)
The issue here is that you are comparing the input object with a KeyCode. You can find the KeyCode inside the input, simply by referencing it.
The code below should work.
local Players = game:GetService("Players") local Player = Players.LocalPlayer local UserInputService = game:GetService("UserInputService") function onInputBegan(input, gameProcessed) if gameProcessed then print(gameProcessed) return end if input.KeyCode == Enum.KeyCode.V then print(input) if Player.CameraMode == Enum.CameraMode.Classic then Player.CameraMode = Enum.CameraMode.LockFirstPerson else Player.CameraMode = Enum.CameraMode.Classic end end end UserInputService.InputBegan:Connect(onInputBegan)