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

How to make a press e to open/close menu?

So i am trying to do a press e key to open menu and i tried this:

local plr = game.Players

plr.GetMouse().KeyDown:Connect(function(K)
	if K == "e" then
		script.Parent.Visible = true
	end
end

end)

It worked for sometime then i left roblox studio trying to get a x button to work and i came back and it no work anymore... Is there something i need to improve or did i do something wrong?

1 comment

0

Just be mindful that if u choose to use "e", this will only work on PC, which is why I just use gui to make it accessible on mobile as well.

2 answers

✓ Accepted answer

Use : instead of . Because you've used

plr.GetMouse()

Replace it to:

plr:GetMouse()

That should work.

Also next time, please use UIS (UserInputService) or CAS (ContextActionService) as KeyDown is deprecated.

EDIT: Replace

local plr = game.Players

To:

local plr = game.Players.LocalPlayer

2 comments

0

Thank you so much!

0

No problem!

Use UserInputService. For example:

local UserInputService = game:GetService("UserInputService")

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

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