Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

UserInputService doesn't want to work, why?

Asked by 3 years ago

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)

1 answer

Log in to vote
1
Answered by
Wiscript 622 Moderation Voter
3 years ago

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)
0
Thanks, I had a look through this. Bankrovers 226 — 3y
Ad

Answer this question