How To Change Character Animations Midgame

Exactly as the title says.

(EXAMPLE) You will seldom need this, but in my case, I want my character to have different run, walk and idle animations when activating their ultimate ability.
After inspecting the feared Roblox Animate script for 4 hours, here’s how you can change the animations midgame (or at least it’s my way of doing it):

=== Replicating The Animate Script ===
If you didn’t know, you can run the game, copy the default Animate script, stop the game, then paste it in StarterCharacterScripts so you can make changes to it it’ll override the default Animate script.
=== Allowing Custom Animations ===
Within the Animate Script on line 138 (approximately), you will see that the function configureAnimationSet will not refresh some values after if the StarterPlayer does not have AllowCustomAnimations turned on. This is bad as we will be relying heavily on configureAnimationSet.

Go to Game Settings, go to Avatar and set Animations to Player Choice

=== Actual Steps ===

  1. Create a new Event Object

Ideally, you will place this Event Instance under the Animate Script itself for convenience purposes. If you want to change animations from the Server, use RemoteEvent (as the Animate script is Local). For the latter (from Client), use BindableEvent.

  1. Store it in a variable inside Animate script

So it should be like this:

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local pose = "Standing"

local ChangeIdEvent = script.ChangeId -- I named the event ChangeId
  1. Somewhere at the bottom (but above the StepAnimate loop at the VERY bottom), attach your ChangeId (or whatever you called it) event so you can change the animation whenever you like, like so:
ChangeIdEvent.OnClientEvent:Connect(function(animName, id)
	local beforeStop = currentAnim
	for _, childAnim in script[animName]:GetChildren() do
		childAnim.AnimationId = id

Okay, now my head hurts, goodbye fellow folks and let me know if this destroys your game or not, goodbye.

Edit: For anyone who might have possibly used the old “refresh” steps, please don’t. The old steps replicated animations blends weirdly on the server and other players will not see your animation the same way you do. Best thing is to use the stopAllAnimations function (although there is a slight stutter, you might have to compensate or cover it up with a transition animation or something along those lines).