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

How could I execute an action when I finished keeping a key pressed for Z seconds?

Asked by 5 years ago
Edited by M39a9am3R 5 years ago

I know how it would be for as long as you keep a key pressed to execute an action but I do not know how it would do so that when you finish holding down a key for Z seconds. Help me

Example of what I did : local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input,obj)

local key = input.KeyCode

if key == Enum.KeyCode.E and not obj then

script.Parent.Frame:TweenSize(UDim2.new(0, 546,0, 43),"InOut","Linear",8,true)

script.Parent.Frame.Visible = true

script.Parent.Frame2.Visible = true

end

end)

0
Edited for title translation. Google translate used. M39a9am3R 3210 — 5y
0
Sorry but i dont speak inglish very good Xaron84 0 — 5y
0
while not uis.InputEnded do DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by
VicyX 27
5 years ago

Instead of InputBegan use InputEnded with similar parameters as InputBegan

Example:

local uis = game:GetService("UserInputService")

uis.InputEnded:Connect(function(input, obj)
    local key = input.KeyCode
    local NotKey = Enum.KeyCode.Z --Replace Z with the key you want to check is not pressed after the amount of seconds
    if key == Enum.KeyCode.E and not obj then
        wait() --Put in number of seconds you want to wait for
        if uis:IsKeyDown(NotKey) then -- If whatever key you chose is not pressed after the amount of time you put then
            --Code
        end
    end
end)
0
This isn't necessary. DeceptiveCaster 3761 — 5y
Ad

Answer this question