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

UserInputService localscript not working?

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

I get no errors when I test it, but nothing happens when I press the KeyCode

0
I want this to function where the menu appears on the screen while the specified key is being pressed, then dissapear as soon at the key is no longer being pressed. Zombie_Panic 13 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Uhh... I just don't like how you write that script.

local UserInputService = game:GetService("UserInputService")

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

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

This will solve your problem. You can't use UserInputService:IsKeyDown(Enum.KeyCode.E), use the method from my script.

0
This sort of works. The problem I have now is that the script is supposed to show a menu while you are holding down the specified key, THEN have is dissapear as soon as you let go of the key. Right now the menu stays on the screen unless you press any other key on the keyboard or mouse. Zombie_Panic 13 — 5y
0
there is an event for UserInputService called 'InputEnded' which fires when you let go of a key SmugNyan 24 — 5y
0
Here ill re edit it AswormeDorijan111 531 — 5y
0
There AswormeDorijan111 531 — 5y
Ad

Answer this question