Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

3 comments

0

Edited for title translation. Google translate used.

0

Sorry but i dont speak inglish very good

0

while not uis.InputEnded do

1 answer

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)

1 comment

0

This isn't necessary.

This discussion is preserved as it was. New answers, comments, and votes are closed.