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

LocalScript keydown script won't function correctly?

Asked by 5 years ago
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

Log in to vote
0
Answered by 5 years ago

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

0
Thank you Zombie_Panic 13 — 5y
Ad

Answer this question