How to Disable Keybind Animations While Chatting

local key = "B"
local Player = game.Players.LocalPlayer
local Character = Player.Character
local AnimationID = "4725687163"
local CharAnimation
game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode[key] then
  animation()
end
end)
function animation()
  if Character then
    local idleanimation = Character:FindFirstChild("AnimationCharacter")
    if CharAnimation then
      CharAnimation:Stop()
    end
    if idleanimation then
      if idleanimation.AnimationId=="rbxassetid://"..AnimationID then
        idleanimation:Destroy()
        return
      end
      idleanimation:Destroy()
    end
    local Animation =Instance.new("Animation",Character)
    Animation.Name= "AnimationCharacter"
    Animation.AnimationId = "rbxassetid://"..AnimationID
    CharAnimation= Character.Humanoid:LoadAnimation(Animation)
    CharAnimation:Play()
  end
end

Here’s a script that makes the player play the animation whenever B is pressed. How do I make it so that the animation will not play clicking B while you are typing a message?
This is a script inside of StarterGui.

3 Likes

Utilize the gameProcessedEvent. It turns either true or false, for instance, if you focus on chat.

I’m not so sure how gameProcessedEvent works

Change the if statement by adding that.

if inputObject.KeyCode == Enum.KeyCode[key] and not gameProcessedEvent then

9 Likes