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

How to make InputEnded only work on specific key?

Asked by
Neon_N 104
6 years ago
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = script.Parent.Humanoid
UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function()
        if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift)then
                humanoid.WalkSpeed = 32
    game.Workspace.CurrentCamera.FieldOfView = 80
end
end)

UserInputService.InputEnded:Connect(function()
    game.Workspace.CurrentCamera.FieldOfView = 70
    humanoid.WalkSpeed = 16
end)

This script make player move faster if shift key is pressed. The problem is whenever I press another key while holding shift, the script ends. How do I only make the script end when I am not holding shift anymore?

0
InputEnded(Key, GameProcessed) works. Tuaz7 30 — 6y

2 answers

Log in to vote
1
Answered by
Tuaz7 30
6 years ago
local Key_Wanted = Enum.KeyCode.LeftShift

local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(Input, gameProcessed)
    if Input.KeyCode == Key_Wanted and not gameProcessed then
        -- do stuff;
    end
end)

UIS.InputEnded:connect(function(Input, gameProcessed)
    if Input.KeyCode == Key_Wanted and not gameProcessed then
        -- undo stuff;
    end
end)
0
Thanks. By the way, what does gameProcessed do? Neon_N 104 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local player = game.Players.LocalPlayer
local Character = player.Character

game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)
    if input.KeyCode == Enum.KeyCode.LeftShift then

        player.Character:WaitForChild("Humanoid").WalkSpeed = 32

    end
end)

game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed)
    if input.KeyCode == Enum.KeyCode.LeftShift then

        player.Character:WaitForChild("Humanoid").WalkSpeed = 16

    end
end)

This should do it

Answer this question