local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Set your animation ID here
local animationId = "rbxassetid://103404072113300"
local animation = Instance.new("Animation")
animation.AnimationId = animationId
local animationTrack
-- Function to play the animation
local function playAnimation()
if not animationTrack then
animationTrack = humanoid:LoadAnimation(animation)
end
if not animationTrack.IsPlaying then
animationTrack:Play()
end
end
-- Function to stop the animation
local function stopAnimation()
if animationTrack and animationTrack.IsPlaying then
animationTrack:Stop()
end
end
-- Connect to the Running event
humanoid.Running:Connect(function(speed)
if speed > 0 and humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
playAnimation()
else
stopAnimation()
end
end)
-- Connect to the Jumping event
humanoid.Jumping:Connect(function(isJumping)
if isJumping then
stopAnimation()
end
end)
-- Additional check for when the character lands
humanoid.StateChanged:Connect(function(_, newState)
if newState == Enum.HumanoidStateType.Freefall then
stopAnimation()
elseif newState == Enum.HumanoidStateType.GettingUp then
stopAnimation()
end
end)