Flashlight (F) turns On/Off while typing

I have a flashlight in game that follows where the mouse is pointing, and to turn it on/off you press F. Only problem is that while typing if I press “F” it still triggers. Is there a way to disable it while the chat bar is up? Thanks master scripters! Here’s the script for the curious:

local UIS = game:GetService(“UserInputService”)

local Enabled = false

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
if not Enabled then
Enabled = true
script.Parent.Range = 60
script.On:Play()
else
Enabled = false
script.Parent.Range = 0
script.Off:Play()
end
end
end)

InputBegan has a second argument, called ProcessedYet. Add that into the function you’re connecting, and do if Processed then return end.

local UIS = game:GetService(“UserInputService”)

local Enabled = false

UIS.InputBegan:Connect(function(input,processed)
   if processed then return end
     if input.KeyCode == Enum.KeyCode.F then
       if not Enabled then
          Enabled = true
          script.Parent.Range = 60
          script.On:Play()
       else
          Enabled = false
          script.Parent.Range = 0
          script.Off:Play()
       end
    end
end)
2 Likes

Thank you so much! I’m very much new to scripting and was wondering for the life of me how to approach this bug!