I always have this problem and sorry if I reposted this (I'm impatient).

problem: idle animation for punching tool stops (its looped) when I walk or jump. punching animations stop sometimes when the character idle animation (not the punching tool idle) plays.

code:

local plr = game.Players.LocalPlayer

local char = plr.Character or plr.CharacterAdded:wait()
local tool = script.Parent
local swingsound = tool:WaitForChild("Swing")
local canattack = tool:WaitForChild("CanAttack")
local deb = false
local cooldown = 1.3
  
tool.Equipped:connect(function()
local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
idle:Play()
end)

tool.Activated:connect(function()
if deb == true then return end
deb = true
local choose = math.random(1,2)
canattack.Value = true
if choose == 1 then
local swing1animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch1)
swingsound:Play()
swing1animation:Play()
wait(cooldown)
deb = false
elseif choose == 2 then
local swing2animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch2)
swingsound:Play()
swing2animation:Play()
wait(cooldown)
deb = false
end
end)

tool.Deactivated:connect(function()
canattack.Value = false
end)

tool.Unequipped:connect(function()
local hum = char:WaitForChild("Humanoid")
for _,anim in pairs(hum:GetPlayingAnimationTracks()) do
anim:Stop()
end
end)

9 comments

0

For starters put this in a code block, next what priority do you have the animation set as?

0

Well the idle animation is looped, the punch animations aren't.

0

animation length for all of them is 1

0

when you upload the animation set its priority to "Action" and for extra measures, you can set it via the script, ex. swing1animation.Priority = Enum.AnimationPriority.Action

0

the idle animation?

0

oh, thanks!

0

Edit:- code block

0

Please do not repost questions. They will be moderated as a duplicate.

0

well when I reset and use the tool, and unequipped it, the idle animation just stays there.