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

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

Asked by 4 years ago

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?

0
idk how to use keydown. User#28017 0 — 4y

2 answers

Log in to vote
1
Answered by
Prestory 1395 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
this didnt work. do you think something else in the script is making this happen? User#28017 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
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.

0
didnt work User#28017 0 — 4y
0
nvm, i messed with my original code, after swapping it back and adding this in it worked User#28017 0 — 4y

Answer this question