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

LocalScript keydown script won't function correctly?

local UserInputService = game:GetService("UserInputService")
local isPressed = UserInputService:IsKeyDown(Enum.KeyCode.E)
if isPressed then
    script.Parent.Visible = true
    else
    script.Parent.Visible = false
end

This is the initial script I had. I don't get any errors when testing it, and nothing happens when I press E.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input)
    if Input.KeyCode == Enum.KeyCode.E then
        --script.Parent.Visible = true
    else
        --script.Parent.Visible = false
    end
end)

This is the script that AswormeDorijan111 gave me. It works... but not in the way i'm wanting it too.

I need the script to open a menu ONLY while the E button on the keyboard is being HELD DOWN. As soon as the button isn't being held down anymore, I want the menu to disapear. Anyone have some help for me?

1 answer

✓ Accepted answer

You need a function to inversely handle when the key is lifted as well, you can use InputEnded for this.

1 comment

0

Thank you

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