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)