How to instantly play new default animation id after changing it in game?

  1. What do you want to achieve?

    I want to instantly play a new Idle animation after changing the animationid

Problem?

 After changing the idle animation id the old idle animation is still playing until you move or jump.

 As you can see, the new animation only plays after you move.
 I am guessing that the new idle animation doesnt play because of humanoidstatetype not changing?

What solutions have you tried so far?

    I have tried searching on the Developer Hub but the only topic that came up was "Detect if player change animation"

Code (Server Script)

game.ReplicatedStorage.WeoponEquipEvent.OnServerEvent:Connect(function(Player, Character, WeoponName)
	
	local IdleOne = Character.Animate.idle.Animation1
	local IdleTwo = Character.Animate.idle.Animation2

	local Walk = Character.Animate.run.RunAnim

	local Jump = Character.Animate.jump.JumpAnim

	local Fall = Character.Animate.fall.FallAnim
	
	local Weopon = game.ReplicatedStorage.WeoponModels:FindFirstChild(WeoponName):Clone()
	Weopon.Parent = Character
	
	local Motor6D = Instance.new("Motor6D")
	
	
	
	Motor6D.Parent = Character:FindFirstChild("HumanoidRootPart")
	Motor6D.Name = "WeoponMotor6D"
	
	Motor6D.Part0 = Character:FindFirstChild("HumanoidRootPart")
	Motor6D.Part1 = Weopon.PrimaryPart
	
	
	
	IdleOne.AnimationId = Weopon:FindFirstChild("Idle").AnimationId
	IdleTwo.AnimationId = Weopon:FindFirstChild("Idle").AnimationId
	
	Walk.AnimationId = Weopon:FindFirstChild("Walk").AnimationId
	
	Jump.AnimationId = Weopon:FindFirstChild("Jump").AnimationId
	
	Fall.AnimationId = Weopon:FindFirstChild("Fall").AnimationId
	
	local EquipAnimation = Instance.new("Animation")
	EquipAnimation.AnimationId = Weopon.Equip.AnimationId
	Character.Humanoid:LoadAnimation(EquipAnimation):Play()
	
end)
3 Likes

You could try to get the current running tracks of every single animation, destroy it and use the animator to load the new ones. Or make sure your idle animation’s priority is idle.

2 Likes

Thanks for the response. I tried it by using this code:

	local AnimationTracks = Character.Humanoid:GetPlayingAnimationTracks()
	for i, track in pairs (AnimationTracks) do
		track:Stop()
	end

However it still got the same result as in the video. I could’ve put it in the wrong place i’m not sure.

game.ReplicatedStorage.WeoponEquipEvent.OnServerEvent:Connect(function(Player, Character, WeoponName)
	
	local IdleOne = Character.Animate.idle.Animation1
	local IdleTwo = Character.Animate.idle.Animation2

	local Walk = Character.Animate.run.RunAnim

	local Jump = Character.Animate.jump.JumpAnim

	local Fall = Character.Animate.fall.FallAnim
	
	local Weopon = game.ReplicatedStorage.WeoponModels:FindFirstChild(WeoponName):Clone()
	Weopon.Parent = Character
	
	local Motor6D = Instance.new("Motor6D")
	
	
	
	Motor6D.Parent = Character:FindFirstChild("HumanoidRootPart")
	Motor6D.Name = "WeoponMotor6D"
	
	Motor6D.Part0 = Character:FindFirstChild("HumanoidRootPart")
	Motor6D.Part1 = Weopon.PrimaryPart
	--- Newly added Code
	local AnimationTracks = Character.Humanoid:GetPlayingAnimationTracks()
	for i, track in pairs (AnimationTracks) do
		track:Stop()
	end
	
	IdleOne.AnimationId = Weopon:FindFirstChild("Idle").AnimationId
	IdleTwo.AnimationId = Weopon:FindFirstChild("Idle").AnimationId
	
	Walk.AnimationId = Weopon:FindFirstChild("Walk").AnimationId
	
	Jump.AnimationId = Weopon:FindFirstChild("Jump").AnimationId
	
	Fall.AnimationId = Weopon:FindFirstChild("Fall").AnimationId
	
	local EquipAnimation = Instance.new("Animation")
	EquipAnimation.AnimationId = Weopon.Equip.AnimationId
	Character.Humanoid:LoadAnimation(EquipAnimation):Play()
	
end)

What kind of plugin / method did you use? I mean I get how you used Moyer parts to match with the idle animation to bend the arm with the tool in the hand but what exactly did you do? If I where you I would play an animation for the arm, this makes it so the feast of the character can move and the arm is caring the sword on the players back.

You can just manipulate the “Animate” script directly like in the above article to change default animations.

I used Moon Animator to animate and the welder that comes with it to weld the primarypart of the model to the HumanoidRootPart

I figured it out. Made it so that it would stop playing the old animation and start playing the new animation by changing humanoidstatetype after the weopon was equipped.

Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Swimming)
2 Likes