Gui opens up whenever the player moves

I got a open/close gui script from a youtube tutorial and added it to my game. I wanted to modify it by making it so that when you press a button, the gui pops up. My problem is that whenever the player moves, the gui pops up even if they don’t press the right buttons. I added my own button press script in there, but then added a button press script that somebody else made because I thought the one I made was flawed somewhere.

here’s the script (containing a script that someone else made)

local frame = script.Parent.Parent.MenuFrame  
local open = false
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")

local Tapped = false
UserInputService.InputBegan:Connect(function(Input, GameStuff)
	if GameStuff then return end
		if Input.KeyCode == Enum.KeyCode.R or Enum.KeyCode.ButtonY then
	if frame.Visible == false then
			frame.Visible = true
			end
		end
end)

I don’t know how to solve this. Please help

local Tapped = false
UserInputService.InputBegan:Connect(function(Input, GameStuff)
	if GameStuff then return end
		if Input.KeyCode == Enum.KeyCode.R or Input.KeyCode == Enum.KeyCode.ButtonY then
	if frame.Visible == false then
			frame.Visible = true
			end
		end
end)
1 Like

You had to do:
if Input.KeyCode == Enum.KeyCode.R or Input.KeyCode == Enum.KeyCode.ButtonY then
instead of:
if Input.KeyCode == Enum.KeyCode.R or Enum.KeyCode.ButtonY then
It’ll account it as a new conditional so you still have to do Input.KeyCode too.

1 Like

Thanks for the explanation! I didn’t know I made that mistake