KeyDown Troubleshooting

Needed help on how to check if a user is holding down a key rather than just pressing it. I’ve checked other topics, but couldn’t find a fix.

local keyCode = Enum.KeyCode.C
local function isSliding()
return userinput:IsKeyDown(keyCode)
end

local function input(_input, _gpe)
if not isSliding() then
player.humanoid.WalkSpeed = 23
else
player.humanoid.WalkSpeed = 2
end
end

userinput.InputBegan:Connect(input)

local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer 

UIS.InputBegan:Connect(function(Input, Processed)
    if (Input.KeyCode == Enum.KeyCode.C) and (not Processed) then 
        repeat
            Player.Character.Humanoid.WalkSpeed = 2
            task.wait()    
        until (UIS:IsKeyDown(Enum.KeyCode.C) == false)
        Player.Character.Humanoid.WalkSpeed = 23
    end
end)


1 Like

You may want to check this out How to check if a key is being held down with UserInputService? - #6 by testattempt

1 Like
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.