How do I stop my Tool Idle Animation?

So I just started scripting like few months ago and then I am making a tool idle script which was supposed to stop when I am walking. So like it will play it own walk animation and stops the idle.

The Issues I was facing is that whenever I unequipped the tool, the tool idle animation stays. And whenever I unequipped the tool when I was walking, if I use the tool again I will be stuck in walking animation.

I tried to find similar topic to me but it ends up even bigger problem. So I return to my old script that has the bug I just explained.

Here is the script that I wrote. Both walking and idle animation was “Action”. I tried making them Idle and Movement but ends up, the walk animation wont stop whenever I started walking.

local tool = script.Parent
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://0"
local track
local Player = game.Players.LocalPlayer
local Char = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Char:WaitForChild("Humanoid")

Humanoid.Running:Connect(function(speed)
	if speed > 0 then
		tool.Equipped:Connect(function()
			local Animation = Instance.new("Animation")
			local Character, Animator, PlayAnim
			Animation.AnimationId = "rbxassetid://0"
			Character = tool.Parent
			Animator = Character:WaitForChild("Humanoid"):WaitForChild("Animator")
			PlayAnim = Animator:LoadAnimation(Animation)
			PlayAnim:Play()
			tool.Unequipped:Connect(function()
				if PlayAnim then
					PlayAnim:Stop()
				end
			end)
		end)
	else
		tool.Equipped:Connect(function()
			track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
			track.Priority = Enum.AnimationPriority.Action
			track.Looped = true
			track:Play()
		tool.Unequipped:Connect(function()
			track:Stop()
			end)
		end)
	end
end)
2 Likes

Use the Idled event to detect when any given player is idle.

https://developer.roblox.com/en-us/api-reference/event/Player/Idled

That did actually work but the new problem arrived. The Idle animation doesnt show up and the Walk Animation will always play.