I’ve not tested this very well, but it might just do the job. Make sure to adjust animation priority so that it trumps the default walking animation.
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Tool = script.Parent
-- Here we load our animation onto the Animator, located inside the Humanoid.
local Animation = Instance.new("Animation")
Animation.AnimationId = "http://www.roblox.com/Asset?ID=14146710555"
local Tool_Walk = Humanoid.Animator:LoadAnimation(Animation)
-- While tool is equipped, the Humanoid.Running event fires whenever a change in speed occurs.
-- We can use this to stop/start the animation and use isWalking as a debug bool value to make sure animations doesnt start/stop rapidly.
local isWalking = false
Humanoid.Running:Connect(function(speed)
if Tool.Parent == Character then
if speed > 0 and not isWalking then
isWalking = true
Tool_Walk:Play()
elseif speed == 0 and isWalking then
isWalking = false
Tool_Walk:Stop()
end
end
end)
Tool.Equipped:Connect(function()
-- Starts animation if player is walking and equips tool
if Humanoid.MoveDirection.Magnitude > 0 then
isWalking = true
Tool_Walk:Play()
end
end)
Tool.Unequipped:Connect(function()
-- Stops animation if player is walking and unequips tool
if Humanoid.MoveDirection.Magnitude > 0 then
isWalking = false
Tool_Walk:Stop()
end
end)