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

How do I check if a key is no longer being pressed?

Asked by 5 years ago

I want to make a sprint button. I know how to bind keys but I don't know how to make the function stop when the sprint button (left shift) is no longer being held down.

2 answers

Log in to vote
1
Answered by 5 years ago

For Client key down you should probably use UserInputService:

local user = game:GetService("UserInputService")
if user:IsKeyDown(Enum.KeyCode.A) then
    repeat
    wait(1)
    print("Key A is down")
    until not user:IsKeyDown(Enum.KeyCode.A) --- Will repeat until the key is not down.
end
Ad
Log in to vote
0
Answered by
Diltz_3 75
5 years ago
Edited 5 years ago

Use a UserInputService and events InputBegan & InputEnded

Service: http://robloxdev.com/api-reference/class/UserInputService

Answer this question