Tool idle animation stops after playing 1 time

(Bad English Warning)

I am trying to create script which will play idle and run animations when holding a tool
However when idle animaton plays ones it just stops

local tool = script.Parent
local animIdle = Instance.new("Animation")
local animRun=Instance.new("Animation")
animIdle.AnimationId = "http://www.roblox.com/Asset?ID=130441953020423"
animRun.AnimationId="http://www.roblox.com/Asset?ID=113670739567202"

local character=script.Parent.Parent.Parent.Character

local trackIdle=character.Humanoid.Animator:LoadAnimation(animIdle)
trackIdle.Priority=Enum.AnimationPriority.Idle
trackIdle.Looped=true
local trackRun=character.Humanoid.Animator:LoadAnimation(animRun)
trackRun.Priority=Enum.AnimationPriority.Movement
trackRun.Looped=true


character.AttributeChanged:Connect(function()
	if character:GetAttribute("HoldingSword") and character:GetAttribute("Moving")  then
		if trackIdle then
			trackIdle:Stop()
		end		
		trackRun:Play()
	elseif character:GetAttribute("HoldingSword") then
		if trackRun then
			trackRun:Stop()
		end
		trackIdle:Play()
	end
end)	
	

tool.Unequipped:Connect(function()
	trackRun:Stop()
	trackIdle:Stop()
end)



1 Like

Did you set the animation to loop in the animator? Sometimes setting it with code doesnt always work

2 Likes

Yea you’ll need to go to the animation and set it so that it loops, then export it again

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.