Scripting Helpers is winding down operations and is now read-only. More info→
Ad
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 186
3 years ago
Edited 3 years 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 — 3y
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 659 — 3y

1 answer

Log in to vote
2
Answered by 3 years ago
Edited 3 years 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 186 — 3y
Ad

Answer this question