I don't know why, but even if I am not pressing "Q", it can hit a humanoid when it's right hand or left hand is near the humanoid
local pressed = false local trackanimation = nil local playability = true local hold = false local value = script:GetChildren("PunchVal") value = 1 function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.Q and not pressed then if playability == true and value == 1 then pressed = true local plr = game.Players.LocalPlayer trackanimation = plr.Character.Humanoid:LoadAnimation(animation1) trackanimation:Play() wait(0.7) pressed = false value = 2 playability = false local Debounce = false local plr = game.Players.LocalPlayer plr.Character.RightHand.Touched:connect(function(hit) if hit.Name ~= "Skill" then local humanoid = hit.Parent:findFirstChild("Humanoid") if humanoid and humanoid ~= plr.Character.Humanoid then if Debounce == false then Debounce = true wait(1) script.Punch1Sound:Play() humanoid:TakeDamage(1) Debounce = false if humanoid:TakeDamage(1) then wait(0.8) end end end end end)
I haven't been able to test this because I don't have the stuff needed in the if statements so hopefully this works!
local trackanimation = nil local playability = true local hold = false local animation1 = nil --GIVE PATH TO ANIMATION HERE local value = script:GetChildren("PunchVal") local deb = true value = 1 function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.Q and deb then if playability == true and value == 1 then deb = false local plr = game.Players.LocalPlayer trackanimation = plr.Character.Humanoid:LoadAnimation(animation1) trackanimation:Play() wait(0.7) value = 2 playability = false local Debounce = false local plr = game.Players.LocalPlayer plr.Character.RightHand.Touched:connect(function(hit) if hit.Name ~= "Skill" then local humanoid = hit.Parent:findFirstChild("Humanoid") if humanoid and humanoid ~= plr.Character.Humanoid then if Debounce == false then Debounce = true script.Punch1Sound:Play() humanoid:TakeDamage(1) end end end end) wait(0.8) deb = true end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)