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

How can i check if a certain hotkey is being held, and when is it released?

Asked by
Echtic 128
5 years ago

Also how can i make some value rapidly increase while that button is being held?

1 answer

Log in to vote
2
Answered by 5 years ago

The answer is pretty simple. You can use the service "UserInputService" to sense when a key is being pressed. For example:

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(key) -- Senses when a key is pressed
    if key == Enum.Key.Q then --Change Q to any key
        --Code
    end
end)

UserInputService.InputEnded:Connect(function(key) -- Senses when a key is let go
    if key == Enum.Key.Q then --Change Q to any key
        --Code
    end
end)
0
Forgot to mention but you can constantly fire a remote event to increase the value Clasterboy 72 — 5y
0
Thanks a lot that's exactly what i needed, could you also send me a link to the developer wiki explaining the whole user input service, i couldn't find it by myself Echtic 128 — 5y
0
Sure, of course! Clasterboy 72 — 5y
0
I'm thankful Echtic 128 — 5y
Ad

Answer this question