Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

My script won't work and won't return any error to the output, I don't understand why?

Asked by
XDvvvDX 171
2 months ago
Edited 2 months ago

Hey. I made a script that whenever a player presses V it will change his CameraMode. For some reason it won't work, and it won't return any error to the output. Here's my script, lines 29-40:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(isTyping, KeyCode)
    if not isTyping then
        if KeyCode.KeyCode == Enum.KeyCode.LeftShift then
            local players = game:GetService("Players")
            local localPlayer = players.LocalPlayer
            local character = localPlayer.Character
            local humanoid = character.Humanoid
            local speed = 19
            humanoid.WalkSpeed = tonumber(speed)
        end
    end
end)

UIS.InputEnded:connect(function(isTyping, KeyCode)
    if not isTyping then
        if KeyCode.KeyCode == Enum.KeyCode.LeftShift then
            local players = game:GetService("Players")
            local localPlayer = players.LocalPlayer
            local character = localPlayer.Character
            local humanoid = character.Humanoid
            local speed = 13
            humanoid.WalkSpeed = tonumber(speed)
        end
    end
end)

UIS.InputBegan:connect(function(isTyping, KeyCode)
    if not isTyping then
        if KeyCode.KeyCode == Enum.KeyCode.V then
            local localPlayer = game.Players.LocalPlayer
            if localPlayer.CameraMode == Enum.CameraMode.Classic then
                localPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
            elseif localPlayer.CameraMode == Enum.CameraMode.LockFirstPerson then
                localPlayer.CameraMode = Enum.CameraMode.Classic
            end
        end
    end
end)

I will make sure to accept the helpful answer!

0
ok you_success -50 — 2mo
0
I'm not sure v has this problem, but certain Enum.KeyCode values will return true for isTyping, because it's really gameProcessedEvent, and it might mean typing, mouseLock, leaderboard, backpack, etc. processed it blowup999 563 — 2mo

1 answer

Log in to vote
2
Answered by 2 months ago
Edited 2 months ago

It's because you have (isTyping, KeyCode). Please note that the order of the parameters do actually matter. The first parameter of this event is the Input and the next is gameProcessedEvent. So in your script, 'isTyping' is being assigned to the Input, and 'KeyCode' is being assigned to gameProcessedEvent. Just switch the parameters around and it should work.

0
I will try it right now. If it will help I will accept your answer. Let me do it very quick. XDvvvDX 171 — 2mo
Ad

Answer this question