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

UserInputService localscript not working?

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

1 comment

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.

1 answer

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.

4 comments

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.

0

there is an event for UserInputService called 'InputEnded' which fires when you let go of a key

0

Here ill re edit it

0

There

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