Having an issue using userinputservice

Hey scripters, I’m having an issue using userinputservice to script an animation. The animation is a punch, but everytime a player hits F in chat when typing, it plays the animation. I only want the animation to play if the user is not typing in the chat or anything. How would I change this script to allow the animation to play, just not when the player is using the chat bar. The code is below.

local db = true
local Humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
local LeftAnim = Humanoid:LoadAnimation(script:WaitForChild("LeftAnimation"))
local character = game.Players.LocalPlayer.Character
local Event = game.ReplicatedStorage.Punch
local dmg
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Sound = script.Punch
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Key)
	
	if Key.KeyCode == Enum.KeyCode.F then
		if db == true then
			Event:FireServer(Player)
			db = false
			dmg = true
			LeftAnim:Play()
			wait()
			dmg = false
			db = true
		end
	end
	
end)

character:WaitForChild("LeftHand").Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")and  dmg == true then
		Sound:Play()
		hit.Parent.Humanoid:TakeDamage(2) -- change 2 By your Any number
		
	end
end)


The InputBegan event has 2 parameters, the input and GameProcessedEvent, also referred to as GPE. This basically means if the user was doing something else, such as typing or clicking on something, then GPE will be true. Using this we can add a simple if statement to return the code if this is the case.

local db = true
local Humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
local LeftAnim = Humanoid:LoadAnimation(script:WaitForChild("LeftAnimation"))
local character = game.Players.LocalPlayer.Character
local Event = game.ReplicatedStorage.Punch
local dmg
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Sound = script.Punch
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Key, GPE)
	
    if GPE then return end

	if Key.KeyCode == Enum.KeyCode.F then
		if db == true then
			Event:FireServer(Player)
			db = false
			dmg = true
			LeftAnim:Play()
			wait()
			dmg = false
			db = true
		end
	end
	
end)

character:WaitForChild("LeftHand").Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")and  dmg == true then
		Sound:Play()
		hit.Parent.Humanoid:TakeDamage(2) -- change 2 By your Any number
		
	end
end)

thank you, I will try that. forgot about that being needed.