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

Making a GUI appear when you aren't typing in the chat?

Asked by 5 years ago

Hello guys, I have simple script that when the "F" button is pressed a GUI appears. However, my only problem with is this is that when in-game and using a word that contains the letter it appears. How would I efficiently make it so that it only appears when you aren't typing in the chat?

Here is the script for reference.

local Frame = script.Parent

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.F then
        Frame.Visible = true
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

1 answer

Log in to vote
0
Answered by
LeadRDRK 437 Moderation Voter
5 years ago
Edited 5 years ago

The second parameter of the InputBegan event is gameProcessedEvent, as defined in your function. It will be true if you are typing on another gui, etc. Acknowledging this, we can use an if statement to check if the gameProcessedEvent is not true, then do the stuff that you wanted:

local Frame = script.Parent

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.F and not gameProcessedEvent then
        Frame.Visible = true
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
0
Thank you very much, i usually write scripts and have a break and completely forget about things.. iChaboyy 7 — 5y
Ad

Answer this question