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

How to toggle an Options Frame if the player isn't typing help?

I created a script that would open/close an Options menu when pressing the "O" key on your keyboard. However, when I tried typing inside a TextBox that the frame "menu" had inside it, it would cut off the menu when I pressed "O". Here's the script:

local uis = game:GetService("UserInputService")
uis.InputBegan:connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then 
		if input.KeyCode == Enum.KeyCode.O then 
			print("Success!")
			local menu = script.Parent.options.menu
			local open = menu.isOpen
			if open.Value == true then -- Menu is open
				menu.Visible = false 
				open.Value = false 
			else -- Menu is not open 
				menu.Visible = true 
				open.Value = true 
			end
		end
	end
end)

The problem is that this script is triggered when "O" is pressed, even when a player is typing in the radio. How do I make this script connect the function when the player is not typing?

1 comment

0

idk how to use keydown.

2 answers

✓ Accepted answer

You need to pass a second argument through the () which is called processed now this detects if the player is chatting etc which is why your having this issue because you are only detecting keyboard input.

local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(InputObject,Processed)
    if not Processed then
        if InputObject.KeyCode == Enum.KeyCode.O then
            print("Success! ")
            local menu = script.Parent.options.menu
            local open = menu.isOpen
            if open.Value == true then -- Menu is open
                menu.Visible = false 
                open.Value = false 
            else -- Menu is not open 
                menu.Visible = true 
                open.Value = true 
            end
        end
    end
end)

1 comment

0

this didnt work. do you think something else in the script is making this happen?

local uis = game:GetService("UserInputService")
uis.InputBegan:connect(function(input,gameprocessed)
	if gameprocessed == false then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.O then
				print("Success!")
				local menu = script.Parent.options.menu
				local open = menu.isOpen
				if open.Value == true then -- Menu is open
					menu.Visible = false
					open.Value = false
				else -- Menu is not open
					menu.Visible = true
					open.Value = true
				end
			end
		end
	end
end)

When the focus is on a gui then gameprocessed will be true. The function will be fired when the focus is not on a gui, so when gameprocessed is false.

2 comments

0

didnt work

0

nvm, i messed with my original code, after swapping it back and adding this in it worked

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