How do I change the running animation while it is playing

I made a running animation that replaces the default running animation when you have a tool equipped, so that the tool doesn’t bob up and down so much, but if you are running and you equip the tool while running it does not play my running animation until the player stops moving.

Video of Problem
robloxapp-20201014-1853248.wmv (2.4 MB)

Local Script

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

script.Parent.Equipped:Connect(function()
	local char = player.character
	char.Animate.walk.WalkAnim.AnimationId = "rbxassetid://5828754975"
	char.Animate.run.RunAnim.AnimationId = "rbxassetid://5828754975"
	
	local idleAnimationTrack = char.Humanoid:LoadAnimation(script.Parent.Animations.IdleAnimation)
	local idleAnimationTrack2 = char.Humanoid:LoadAnimation(script.Parent.Animations.IdleAnimation2)
	idleAnimationTrack:Play()
	wait(0.3)
	idleAnimationTrack2:Play()
	
	
	script.Parent.Unequipped:Connect(function()
		char.Animate.walk.WalkAnim.AnimationId = "rbxassetid://2510198475"
		char.Animate.run.RunAnim.AnimationId = "rbxassetid://2510198475"

		idleAnimationTrack:Stop()
		idleAnimationTrack2:Stop()
	end)
end)

This should be in scripting support and not cool creations.

1 Like

perhaps you can check if the player is running in the equip part and not do the equip.

how do I check if the player is running?

from a quick search I got

You can check if player is running by event

Humanoid.Running:Connect(function()
end)

Replace the default animation required

I do these operations, you can try it

Use a StringValue to store the AnimationId that I want to replace

tool.Equipped:Connect >>>>>> Store AnimationId in StringValue

tool.Unequipped:Connect >>>>>> Use the value stored in StringValue

Tool

local tool = script.Parent
tool.RequiresHandle = false
tool.CanBeDropped = false 

tool.Equipped:Connect(function()
	
	local humanoid = script.Parent.Parent:WaitForChild("Humanoid")
	
	for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
		playingTracks:Stop(0)
	end
	
	local animateScript = script.Parent.Parent:WaitForChild("Animate")
	
	script.Parent.runValue.Value = animateScript.run.RunAnim.AnimationId
	animateScript.run.RunAnim.AnimationId = "rbxassetid://616163682"        -- Run
	
	script.Parent.walkValue.Value = animateScript.walk.WalkAnim.AnimationId
	animateScript.walk.WalkAnim.AnimationId = "rbxassetid://616168032"      -- Walk
	
	script.Parent.jumpValue.Value = animateScript.jump.JumpAnim.AnimationId
	animateScript.jump.JumpAnim.AnimationId = "rbxassetid://616161997"      -- Jump
	
	script.Parent.idle1Value.Value = animateScript.idle.Animation1.AnimationId
	animateScript.idle.Animation1.AnimationId = "rbxassetid://616158929"    -- Idle (Variation 1)
	
	script.Parent.idle2Value.Value = animateScript.idle.Animation2.AnimationId
	animateScript.idle.Animation2.AnimationId = "rbxassetid://616160636"    -- Idle (Variation 2)
	
	script.Parent.fallValue.Value = animateScript.fall.FallAnim.AnimationId
	animateScript.fall.FallAnim.AnimationId = "rbxassetid://616157476"      -- Fall
	
	script.Parent.swimValue.Value = animateScript.swim.Swim.AnimationId
	animateScript.swim.Swim.AnimationId = "rbxassetid://616165109"          -- Swim (Active)
	
	script.Parent.swimidleValue.Value = animateScript.swimidle.SwimIdle.AnimationId
	animateScript.swimidle.SwimIdle.AnimationId = "rbxassetid://616166655"  -- Swim (Idle)
	
	script.Parent.climbValue.Value = animateScript.climb.ClimbAnim.AnimationId
	animateScript.climb.ClimbAnim.AnimationId = "rbxassetid://616156119"    -- Climb
	
end)

tool.Unequipped:Connect(function()
	
	local humanoid = script.Parent.Parent.Parent.Character :WaitForChild("Humanoid")
	
	for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
		playingTracks:Stop(0)
	end
	
	local animateScript = script.Parent.Parent.Parent.Character:WaitForChild("Animate")
	
	animateScript.run.RunAnim.AnimationId = script.Parent.runValue.Value        -- Run
	
	animateScript.walk.WalkAnim.AnimationId = script.Parent.walkValue.Value      -- Walk
	
	animateScript.jump.JumpAnim.AnimationId = script.Parent.jumpValue.Value      -- Jump
	
	animateScript.idle.Animation1.AnimationId = script.Parent.idle1Value.Value    -- Idle (Variation 1)
	
	animateScript.idle.Animation2.AnimationId = script.Parent.idle2Value.Value    -- Idle (Variation 2)
	
	animateScript.fall.FallAnim.AnimationId = script.Parent.fallValue.Value      -- Fall
	
	animateScript.swim.Swim.AnimationId = script.Parent.swimValue.Value          -- Swim (Active)
	
	animateScript.swimidle.SwimIdle.AnimationId = script.Parent.swimidleValue.Value  -- Swim (Idle)
	
	animateScript.climb.ClimbAnim.AnimationId = script.Parent.climbValue.Value    -- Climb
	
end)

If it doesn’t work properly, tell me about the problem

I wish you good luck in what you do

This is a short code that replaces only one AnimationId

Tool

local tool = script.Parent
tool.RequiresHandle = false
tool.CanBeDropped = false 

tool.Equipped:Connect(function()
	
	local humanoid = script.Parent.Parent:WaitForChild("Humanoid")
	
	for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
		playingTracks:Stop(0)
	end
	
	local animateScript = script.Parent.Parent:WaitForChild("Animate")
	
	script.Parent.runValue.Value = animateScript.run.RunAnim.AnimationId
	animateScript.run.RunAnim.AnimationId = "rbxassetid://616163682"        -- Run
	
end)

tool.Unequipped:Connect(function()
	
	local humanoid = script.Parent.Parent.Parent.Character :WaitForChild("Humanoid")
	
	for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
		playingTracks:Stop(0)
	end
	
	local animateScript = script.Parent.Parent.Parent.Character:WaitForChild("Animate")
	
	animateScript.run.RunAnim.AnimationId = script.Parent.runValue.Value        -- Run
	
end)

What you showed in the video already works for me, the problem is that I can’t get my running animation to stop the default running animation from playing if I pull out the tool while my character is moving.

Change the running animation while it is playing

I hope this code helps you

You don’t need any plugins, just copy and paste the code in LocalScript in Tool

Run the code in Studio before changing anything

Tool

local tool = script.Parent
tool.RequiresHandle = false
tool.CanBeDropped = false

tool.Equipped:Connect(function()
	
	if not script:FindFirstChild("unequi") and not script:FindFirstChild("equi") then
		
	local animateScript = script.Parent.Parent:WaitForChild("Animate")
	
	local unequi = Instance.new("Animation")
	unequi.Name = "unequi"
	unequi.AnimationId = animateScript.run.RunAnim.AnimationId
    unequi.Parent = script

    local equi = Instance.new("Animation")
	equi.Name = "equi"
	equi.AnimationId = "rbxassetid://616163682"
    equi.Parent = script
		
	end
	
	local humanoid = script.Parent.Parent:WaitForChild("Humanoid")
	
    local equi = humanoid:LoadAnimation(script.equi)
	
	for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
	if playingTracks.Name == "RunAnim" then	
		equi:Play()
	end
	end
	
	local animateScript = script.Parent.Parent:WaitForChild("Animate")
	animateScript.run.RunAnim.AnimationId = "rbxassetid://616163682"        -- Run
		
end)

tool.Unequipped:Connect(function()
	
	local humanoid = script.Parent.Parent.Parent.Character :WaitForChild("Humanoid")
	
    local unequi = humanoid:LoadAnimation(script.unequi)
	
	for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
	if playingTracks.Name == "RunAnim" then	
		unequi:Play()
	end
	end
	
	local animateScript = script.Parent.Parent.Parent.Character:WaitForChild("Animate")
	animateScript.run.RunAnim.AnimationId = script.unequi.AnimationId       -- Run
	
end)
2 Likes