AnimationsServer
NOTE
Roblox model path: Animations\Package\AnimationsServer
Types
initOptions
interface initOptions {AutoLoadAllPlayerTracks: falseAutoRegisterPlayers: trueBootstrapDepsFolder: Folder?TimeToLoadPrints: false}For more info, see Properties.
path
type path = {any} | stringThese are all valid forms of paths to animation tracks you have defined in the AnimationIds module:
local path = "Jump" -- A single key (any type)
local path = {"Dodge", Vector3.xAxis} -- An array path (values of any type)
local path = "Climb.Right" -- A string path separated by "."
Animations:PlayTrack(player, path)
customRBXAnimationIds
interface customRBXAnimationIds {run: number?walk: number?jump: number?idle: {Animation1: number?,Animation2: number?}?fall: number?swim: number?swimIdle: number?climb: number?}A table of animation ids to replace the default roblox animation ids.
NOTE
The "walk" animation is used for both walking and running on R6 characters.
humanoidRigTypeToCustomRBXAnimationIds
interface humanoidRigTypeToCustomRBXAnimationIds {[Enum.HumanoidRigType.R6]: customRBXAnimationIds?[Enum.HumanoidRigType.R15]: customRBXAnimationIds?}A table mapping a Enum.HumanoidRigType to its supported animation ids that will replace the default roblox animation ids.
Properties
AutoLoadAllPlayerTracks
AnimationsServer.AutoLoadAllPlayerTracks: falseIf set to true, all player animation tracks will be loaded for each player character on spawn.
AutoRegisterPlayers
AnimationsServer.AutoRegisterPlayers: trueIf set to true, all player characters will be auto registered with rigType of "Player" when they spawn.
BootstrapDepsFolder
AnimationsServer.BootstrapDepsFolder: Folder?Set to the dependencies folder if you have moved it from its original location inside of the root Animations folder.
TimeToLoadPrints
AnimationsServer.TimeToLoadPrints: trueIf set to true, makes helpful prints about the time it takes to pre-load and load animations.
PreloadAsyncProgressed
AnimationsServer.PreloadAsyncProgressed: RBXScriptSignalFires when ContentProvider:PreloadAsync() finishes pre-loading one animation instance.
Animations.PreloadAsyncProgressed:Connect(function(n, total, loadedAnimInstance)
print("ContentProvider:PreloadAsync() finished pre-loading one animation:", n, total, loadedAnimInstance)
end)
Functions
Init
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsInitializes AnimationsServer. Clients are unable to initialize until this gets called.
Yields when...
- ...animations are being pre-loaded with
ContentProvider:PreloadAsync()(could take a while).
important
Must be called once before any other method.
GetTrackStartSpeed
If set with HasProperties, returns the animation track's StartSpeed.
GetTimeOfMarker
AnimationsServer:GetTimeOfMarker(markerName: string) → number?
This method can yield if the
initialization process that caches all of the marker
times is still going on when this method is called. If
after 3 seconds the initialization process has still not
finished, this method will return nil.
WARNING
This method only works on animations which you give
the MarkerTimes property to.
local attackAnim = Animations:PlayTrack("Attack")
local timeOfHitStart = Animations:GetTimeOfMarker(attackAnim, "HitStart")
print("Time of hit start:", timeOfHitStart)
-- or
local animIdStr = Animations:GetAnimationIdString("Player", "Attack")
local timeOfHitStart = Animations:GetTimeOfMarker(animIdStr, "HitStart")
print("Time of hit start:", timeOfHitStart)
GetAnimationIdString
Returns the animation id string under rigType at path in the AnimationIds module.
local animIdStr = Animations:GetAnimationIdString("Player", "Run")
print(animIdStr) --> "rbxassetid://89327320"
FindFirstRigPlayingTrack
Returns a playing animation track found in
rig.Humanoid.Animator:GetPlayingAnimationTracks()
matching the animation id found at path in the
AnimationIds module or nil.
WARNING
For this to work, rig needs to be registered.
local isBlocking = Animations:FindFirstRigPlayingTrack(rig, "Blocking")
if isBlocking then
warn("We can't hit the enemy, they're blocking!")
end
WaitForRigPlayingTrack
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
Yields until a playing animation track is found in
rig.Humanoid.Animator:GetPlayingAnimationTracks()
matching the animation id found at path in the
AnimationIds module then returns it or returns nil after
timeout seconds if provided.
WARNING
For this to work, rig needs to be registered.
local isBlocking = Animations:WaitForRigPlayingTrack(rig, "Blocking", 1)
if isBlocking then
warn("We can't hit the enemy, they're blocking!")
end
GetAppliedProfileName
Returns the player_or_rig's currently applied animation profile name or nil.
AwaitPreloadAsyncFinished
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsYields until ContentProvider:PreloadAsync() finishes pre-loading all animation instances.
local loadedAnimInstances = Animations:AwaitPreloadAsyncFinished()
print("ContentProvider:PreloadAsync() finished pre-loading all animations:", loadedAnimInstances)
Register
Registers the player_or_rig so that methods using animation tracks can be called.
TIP
Automatically calls rig:SetAttribute("AnimationsRigType", rigType) which is useful for determining rig types.
AwaitRegistered
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsYields until the player_or_rig gets registered.
IsRegistered
Returns true if the player_or_rig is registered.
ApplyCustomRBXAnimationIds
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsAnimationsServer:ApplyCustomRBXAnimationIds(humanoidRigTypeToCustomRBXAnimationIds: humanoidRigTypeToCustomRBXAnimationIds) → ()Applies the animation ids specified in the humanoidRigTypeToCustomRBXAnimationIds table on the player_or_rig.
Yields when...
- ...the player's character, player or rig's humanoid, player's animator, or player or rig's animate script aren't immediately available.
WARNING
This function only works for players and R6/R15 NPCs that have an "Animate" script in their model.
Animations:ApplyCustomRBXAnimationIds(player, {
[Enum.HumanoidRigType.R15] = {
jump = 656117878,
idle = {
Animation1 = 656117400,
Animation2 = 656118341
}
}
})
GetAnimationProfile
AnimationsServer:GetAnimationProfile(animationProfileName: string) → animationProfilehumanoidRigTypeToCustomRBXAnimationIds?Returns the humanoidRigTypeToCustomRBXAnimationIds table from the animation profile module or nil.
INFO
For more info, see animation profiles.
ApplyAnimationProfile
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsAnimationsServer:ApplyAnimationProfile() → ()Applies the animation ids found in the animation profile on the player_or_rig.
Yields when...
- ...the player's character, player or rig's humanoid, player's animator, or player or rig's animate script aren't immediately available.
WARNING
This function only works for players and R6/R15 NPCs that have an "Animate" script in their model.
INFO
For more info, see animation profiles.
AwaitAllTracksLoaded
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsYields until all the player_or_rig's animation tracks have loaded.
AwaitTracksLoadedAt
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsYields until the player_or_rig's animation tracks have loaded at path.
AreAllTracksLoaded
Returns true if the player_or_rig has had all its animation tracks loaded.
AreTracksLoadedAt
Returns true if the player_or_rig has had its animation tracks loaded at path.
LoadAllTracks
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsCreates animation tracks from all animation ids in AnimationIds for the player_or_rig.
Yields when...
- ...
player_or_rig's animator is not a descendant ofgame.
LoadTracksAt
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsCreates animation tracks from animation ids in AnimationIds for the player_or_rig at path.
Yields when...
- ...
player_or_rig's animator is not a descendant ofgame.
GetTrack
Returns a player_or_rig's animation track or nil.
PlayTrack
Returns a playing player_or_rig's animation track.
StopTrack
Returns a stopped player_or_rig's animation track.
StopPlayingTracks
Returns the stopped player_or_rig animation tracks.
GetPlayingTracks
Returns playing player_or_rig animation tracks.
StopTracksOfPriority
Returns the stopped player_or_rig animation tracks.
GetTrackFromAlias
Returns a player_or_rig's animation track or nil.
PlayTrackFromAlias
Returns a playing player_or_rig's animation track.
StopTrackFromAlias
Returns a stopped player_or_rig's animation track.
SetTrackAlias
Sets an alias to be the equivalent of the path for a player_or_rig's animation track.
TIP
You can use the alias as the last key in the path. Useful for a table of animations. Example:
local AnimationIds = {
Player = {
FistsCombat = {
-- Fists 3 hit combo
Combo = {
[1] = 1234567,
[2] = 1234567,
[3] = 1234567
},
-- Fists heavy attack
HeavyAttack = 1234567
},
SwordCombat = {
-- Sword 3 hit combo
Combo = {
[1] = 1234567,
[2] = 1234567,
[3] = 1234567
},
-- Sword heavy attack
HeavyAttack = 1234567
}
}
}
return AnimationIds
local player = game.Players.wrello
-- After the player's animation tracks are loaded...
local heavyAttackAlias = "HeavyAttack" -- We want this alias in order to call Animations:PlayTrackFromAlias(player, heavyAttackAlias) regardless what weapon is equipped
local currentEquippedWeapon
local function updateHeavyAttackAliasPath()
local alias = heavyAttackAlias
local path = currentEquippedWeapon .. "Combat"
Animations:SetTrackAlias(player, alias, path) -- Running this will search first "path.alias" and then search "path" if it didn't find "path.alias"
end
local function equipNewWeapon(weaponName)
currentEquippedWeapon = weaponName
updateHeavyAttackAliasPath()
end
equipNewWeapon("Fists")
Animations:PlayTrackFromAlias(player, heavyAttackAlias) -- Plays "FistsCombat.HeavyAttack" on the player's character
equipNewWeapon("Sword")
Animations:PlayTrackFromAlias(player, heavyAttackAlias) -- Plays "SwordCombat.HeavyAttack" on the player's character
RemoveTrackAlias
Removes the alias for a player_or_rig's animation track.
AttachWithMotor6d
AnimationsServer:AttachWithMotor6d() → ()Attaches the model to the player_or_rig using the motor6dToClone or the first motor6d found as a child of the model in order to animate it.
In either case, the motor6d used must have the following attributes set:
"Part0Name"- the name of thePart0of themotor6dduring the animation."Part1Name"- the name of thePart1of themotor6dduring the animation.
SetRightGripWeldEnabled
Enables/disables the RightGrip weld that is automatically added to a character's right hand when a tool is equipped.
FindRightGripWeld
Returns the RightGrip weld that is automatically added to a character's right hand when a tool is equipped or nil.
WaitForRightGripWeld
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsYields until the RightGrip weld that is automatically added to a character's right hand when a tool is equipped is found and then returns it.