Animations only changing whenever the player stops moving

Heya.

I’m trying to find a way to change the player’s animation without having the player to stop moving for said animations to change. Here’s a video of what I mean:

Tool.Equipped:Connect(function()
	Humanoid.WalkSpeed = 20
	
	Character.Animate.idle.Animation1.AnimationId = "rbxassetid://18538767403"
	Character.Animate.idle.Animation2.AnimationId = "rbxassetid://18538767403"
	Character.Animate.run.RunAnim.AnimationId = "rbxassetid://18538881589"
	Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://18538881589"
	
	Tool.Unequipped:Connect(function()
		Humanoid.WalkSpeed = 16

		Character.Animate.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id=180435571"
		Character.Animate.idle.Animation2.AnimationId = "http://www.roblox.com/asset/?id=180435792"
		Character.Animate.run.RunAnim.AnimationId = "http://www.roblox.com/asset/?id=180426354"
		Character.Animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=180426354"
	end)
end)

Since the Player is already playing the default diode animation when you have the tool unequipped, I think the best solution is having to manually load, so you can run :Play() to override the already-playing animation. Here’s what I mean:


local animator = Character:FindFirstChildOfClass(“Humanoid”).Animator
local idleAnimObject1 = Instance.new(“Animation”)
idleAnimObject.AnimationId = “rbxassetid://18538767403”
local toolIdleAnim1 = animator:LoadAnimation(idleAnimObject1)

-- Insert other animations here…

Tool.Equipped:Connect(function()


	Humanoid.WalkSpeed = 20
	
    toolIdleAnim1:Play()
end)

So basically just overriding the players default animations with mines to give the illusion it changed? Sounds good to me.
Although I don’t want to constantly copy and paste the same code over and over again. Isn’t there a way to include a table filled with animation id’s then simply make a script that automatically makes animation tracks with the animation id’s and so on?

Yes, using a for loop. You’ll need to include an empty variable for the loaded animations, like:

local animationIds = {
   [“idleAnim1”] = “rbxassetid://18538767403”,
   [“somethingelse”] = “somethingelse…”,
}
local idleAnim1
-- Add other variables referencing to your respective animations here…

local animator = Character:FindFirstChildOfClass(“Humanoid”).Animator

for animName, animationIds in pairs (animationIds) do
   local animationObject = Instance.new(“Animation”)
   animationObject.AnimationId = animationIds
   toolAnim = animator:LoadAnimation(idleAnimObject1)
   if animName == “idleAnim1”
      idleAnim1 = toolAnim
   elseif animName == “”

   end
end

Alright, thanks! I’ll be using this in future projects!

Simple, whenever tool is Unequipped, use Animator:GetPlayingAnimationTracks() to stop your weapon holding animation. (Make sure to check if track.Name or track.Animation is the real one.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.