Animate Local Script, why it’s limited
The Animate LocalScript is limited, but why? Let’s say you wanted to update animations, but you wanted to change the animation or you wanted to stop all playing animations. How would you do it? Here comes the Animate Module!
Animate Module
The Animate Module makes everything easier. It has a module for AnimateValues instead of StringValues with Animations in it. This is a module which has all the functions in the animation LocalScript.
Why This Module is Better Than Animate LocalScript
This module is much better than the Animate LocalScript because:
-
This is a ModuleScript, and it does not work with values that hold animations, but with another module (except for the
ScaleDampeningPercent
). -
(adding onto
1
) You can communicate with this since it is a ModuleScript, unlike the LocalScript. You would need to copy and paste the LocalScript to handle animations, especially changing them. You shouldn’t have to do this. If you were to do complex tasks, you would definitely need a module for this, especially when you need to follow DRY (Don’t Repeat Yourself). This is the reason why I made this module. -
Compatible with both
R6
andR15
, so you don’t have to worry about separate scripts withR15
.
Animate.AnimateValues
This is a module which holds animations (similar to the animNames variable in the Animate LocalScript). There are two separate tables for animations, R6_animNames
and R15_animNames
. These two tables include a getter function (GetAnimation
) and a function you can use to configure the animation (ConfigureAnimation
). The return value is a dictionary, which has three values in it: animNames, dances, emoteNames. animNames is a multi-dimensional dictionary that holds R6 for R6_animNames and R15 for R15_animNames. dances is simply a table that holds the dances ("dance1", "dance2", "dance3"
). emoteNames is another dictionary which holds all the emote names as keys and booleans as values.
animNames:GetAnimation
This method takes in an animation name as its first argument. It will return a given animation. You shouldn’t use this method for configuring animations since there’s already another method for that.
local Character = script.Parent
local AnimationValues = require(Character.Animate.AnimationValues)
-- There may be different tables of animation info for a certain
-- animation.
print(AnimationValues.animNames.R6:GetAnimation("walk")[1].id)
animNames:ConfigureAnimation
This method calls :GetAnimation
with its name parameter. Then, it needs to find out the which animation you want (You’ll see later). Finally, the last argument is the new id. The snippet below is an example you can find in the Model.
-- assuming you have made a variable for the AnimationValue module
AnimationValues.animNames.R6:ConfigureAnimation(
"walk",
1,
AnimationValues.animNames.R6:GetAnimation("dance2") [1].id
)
If you wanted to configure the R15
animations, you would have to do that manually since R6
and R15
are separate rigs.
Animate
This is a Module which returns the :Initialize
method of the module. The method, of course, returns self
, the Animate class. It detects if emotes are played, and it connects the Humanoid state types. Since this module is very long, you should only need to know the most important functions.
Animate.new
A constructor which takes in the Figure
parameter, usually a character. It returns a metatable.
Animate:EndCurrentAnimTrack
A method used to stop the current playing animation. May be used to keep the
Figure
static.
Animate:GetAnim
Although this is used for self.animNames
, it may be useful for getting animations according to the Figure's
rig type (R6
or R15
)
Animate:createAnimationSet
Creates an animation set in self.animTable
; getting a fileset in self.animNames
, and the dictionary name is the name argument.
Animate:setupAnimations
Sets up all the animations by calling self:createAnimationSet
. Iterates through all the animations in self.animNames
and passes the arguments to the method accordingly.
Animate:stopAllAnimations
Another way to stop animations, but truly. It disconnects the self.currentAnimKeyframeHandler
and resets animations.
Animate:playAnimation
Gets animation using self:GetAnim
and the name
argument of the method. It also calls self:rollAnimation
(an internal function) that gets which index to get from the animation table. The method stops the self.currentAnimTrack
with the transitionTime
argument. The animation will load and play from the humanoid
argument (I’m not sure why there is a humanoid argument in the Animate LocalScript. I may remove it from the ModuleScript).
Animate:playToolAnimation
Similar to self:playAnimation
, but it has an extra paremeter (priority), and it works with tools.
Animate:stopToolAnimations
Similar to self:stopAllAnimations
, but it only works with Tool
animations
Animate:SetPose
A setter for the pose
property. It is set to the NewPose
argument of the method.
Animate State Types
There are many functions (onRunning
, onSwimming
etc.). These functions are connected to many Humanoid state types. They also call self:SetPose
to update the pose.
Animate:move
The most important part of the API. This checks the poses and plays animations according to the pose. In the Animate:Initialize
function, this function is called infinitely until the Figure is nil.
Animate:Initialize
This is a Module which returns the :Initialize
method of the module. The method, of course, returns self
, the Animate class. It detects if emotes are played, and it connects the Humanoid state types to the functions mentioned in the “Animate State Types” subtitle.
Here’s the link: Animate Module