Playing an idle animation only when the player is not doing anything else

I have an idle animation playing on the player when a tool is equipped. The issue is that it also overrides any other movement animations like running or jumping.

I want to make it so the idle animation still plays, but does not overwrite stuff like running or jumping.

How could I do this?

Script:

local tool = script.Parent
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/Asset?ID=AnimationID" -- Replaced ID
local track
tool.Equipped:Connect(function()
	track = script.Parent.Parent.Humanoid.Animator:LoadAnimation(anim)
	track.Priority = Enum.AnimationPriority.Action
	track.Looped = true
	track:Play()
end)
tool.Unequipped:Connect(function()
	if track then
		track:Stop()
	end
end)

Why don’t you just replace the default idling animation? This DevForum thread may guide you in the right direction: Changing Default Animations, is there an easy way to do it? - #4 by DJX_D
You can just change the animations in your player’s character based on whether the tool is equipped or not, with using Tool.Equipped and Tool.Unequipped events.