Overwrite running animations when a tool is equipped

Alright, here’s the main issue. Whenever I open up a tool that has a set of animations (Run anim, walk anim, and idle anim(s)) it is set up to replace the main animations on equip and put back the main animations on de-quips. It does this by stopping all animation tracks, setting the animations to the ones I want to use, but I am missing the next part. Unless I stop to idle when running or vice versa, since I ended the previous animation tracks w/o update, they have the character in the no anim pose. Without stopping previous animations, the previous tracks keep playing, such as the idle keeps using the old one until i move or do something that would update it.

Here is my (really bad) code:

organimidle = "rbxassetid://18622358007"
organimrun = "rbxassetid://18623845740"


script.Parent.Equipped:Connect(function()
	
	for i,v in ipairs(script.Parent:GetChildren()) do
		if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("BasePart") then
			if v.Anchored then
				v.Anchored = false
			end
		end
	end
	
	hum =  script.Parent.Parent.Humanoid
	anim = script.Parent.Parent:FindFirstChild("Animate")
	anim.run.RunAnim.AnimationId = "rbxassetid://18817923614" --"rbxassetid://18624348426"
	anim.walk.WalkAnim.AnimationId = "rbxassetid://18817923614"
	anim.idle.Animation1.AnimationId = "rbxassetid://18622750448"
	anim.idle.Animation2.AnimationId = "rbxassetid://18622750448"	
	
	for _, playingTrack in hum.Animator:GetPlayingAnimationTracks() do
		playingTrack:Stop(0)
	end
	
	
	
			--local Run = Instance.new("Animation")
			--Run.AnimationId ="rbxassetid://18817923614"
			--local ranTrack = hum:LoadAnimation(Run)
			--ranTrack.Priority = Enum.AnimationPriority.Movement
			--ranTrack.Looped = true
			--local Walk = Instance.new("Animation")
			--Walk.AnimationId = "rbxassetid://18817923614"
			--local wanTrack = hum:LoadAnimation(Walk)
			--wanTrack.Priority = Enum.AnimationPriority.Movement
			--wanTrack.Looped = true
	
	
end)

cycle = 1

local slash1 = Instance.new("Animation")
slash1.AnimationId = "rbxassetid://18622720414"

local slash2 = Instance.new("Animation")
slash2.AnimationId = "rbxassetid://18622725097"

local slash3 = Instance.new("Animation")
slash3.AnimationId = "rbxassetid://18622729087"

local slash4 = Instance.new("Animation")
slash4.AnimationId = "rbxassetid://18622731997"

script.Parent.Activated:Connect(function()
	
	if cycle == 1 then
		local animationTrack = hum:LoadAnimation(slash1)
		animationTrack:Play();
		cycle = 2
		script.Parent.Enabled = false
		animationTrack.Stopped:Wait()
		script.Parent.Enabled = true

	elseif cycle == 2 then
		local animationTrack = hum:LoadAnimation(slash2)
		animationTrack:Play();
		cycle = 3
		script.Parent.Enabled = false
		animationTrack.Stopped:Wait()
		script.Parent.Enabled = true
	elseif cycle == 3 then
		local animationTrack = hum:LoadAnimation(slash3)
		animationTrack:Play()
		cycle = 4
		script.Parent.Enabled = false
		animationTrack.Stopped:Wait()
		script.Parent.Enabled = true
	else
		local animationTrack = hum:LoadAnimation(slash4)
		animationTrack:Play()
		cycle = 1
		script.Parent.Enabled = false
		animationTrack.Stopped:Wait()
		script.Parent.Enabled = true
	end
end)



script.Parent.Unequipped:Connect(function()
	anim.run.RunAnim.AnimationId = organimrun
	anim.walk.WalkAnim.AnimationId = organimrun
	anim.idle.Animation1.AnimationId = organimidle
	anim.idle.Animation2.AnimationId = organimidle
end)

Its just if you hold W,A,S, or D and equip the tool, it doesn’t switch to new animations. I’ve tried all I know, and digging the forums, but no avail.

1 Like

What I would do is use the AnimationPriority enums (Idle = Action, Walk/Run = Action2, Attacks = Action3)

Hey, just so you know this post belongs in the help category. If you need any help find it, let me know!

Should be good(?), never used the forums for posting stuff.

alr tried that stuff (most of it got deleted but i commented out a section for some reason)

You fixed it! Try to keep the appropriate category, totally understandable if this is your first time.

1 Like

I believe if you swap out the Animation instance instead of just changing the AnimationId the Animate script will automatically change the running animation.

So:

  • Create a new Animation with your custom running animation’s ID
  • When you want to start the new running animation:
    • Set the parent of the current Animation under “run” to nil and store it in a variable
    • Place your custom Animation under “run”
    • When you want to swap back, put the original Animation back under run and remove yours

This is a little confusing, could you re-word a bit?

1 Like

Sure! Instead of just setting the AnimationId:

anim.run.RunAnim.AnimationId = "rbxassetid://18817923614"

swap the entire Animation instance out:

local customAnimation = Instance.new("Animation")
customAnimation.AnimationId = "rbxassetid://18817923614"

-- When you want to change the animation:
local originalAnimation = anim.run.RunAnim
originalAnimation.Parent = nil
customAnimation.Parent = anim.run

-- When you want to change the animation back:
customAnimation.Parent = nil
originalAnimation.Parent = anim.run
1 Like

You could change the animation values in the default Animate script.