AnimationsServer
NOTE
Roblox model path: Animations.Package.AnimationsServer
Types
initOptions
interface initOptions {AutoLoadAllPlayerTracks: falseTimeToLoadPrints: falseEnableAutoCustomRBXAnimationIds: falseAnimatedObjectsDebugMode: falseDepsFolderPath: string?--
Only use if you've moved the 'Deps' folder from its original location.
}Gets applied to Properties.
path
type path = {any} | string-- In a ServerScript
local Animations = require(game.ReplicatedStorage.Animations.Package.AnimationsServer)
-- These are all valid options for retrieving an animation track
local animationPath = "Jump" -- A single key (any type)
local animationPath = {"Dodge", Vector3.xAxis} -- An array path (values of any type)
local animationPath = "Climb.Right" -- A path seperated by "." (string)
local animationTrack = Animations:GetTrack(player, animationPath)
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.
INFO
Roblox applies the "walk" animation id for R6 characters and the "run" animation id for R15 characters (instead of both).
humanoidRigTypeToCustomRBXAnimationIds
interface humanoidRigTypeToCustomRBXAnimationIds {[Enum.HumanoidRigType.R6]: customRBXAnimationIds?[Enum.HumanoidRigType.R15]: customRBXAnimationIds?}A table mapping a humanoid rig type to its supported animation ids that will replace the default roblox animation ids.
Properties
DepsFolderPath
AnimationsServer.DepsFolderPath: nilSet the path to the dependencies folder if you have moved it from its original location inside of the root Animations folder.
added in version 2.0.0-rc1
AutoLoadAllPlayerTracks
AnimationsServer.AutoLoadAllPlayerTracks: falseIf set to true, all player animation tracks will be loaded for each player character on spawn.
WARNING
Must have animation ids under rigType of "Player" in the AnimationIds module.
changed in version 2.0.0-rc1
Renamed: -> AutoLoadPlayerTracksAutoLoadAllPlayerTracks
TimeToLoadPrints
AnimationsServer.TimeToLoadPrints: trueIf set to true, makes helpful prints about the time it takes to pre-load and load animations.
changed in version 2.0.0-rc1
Defaults to true.
EnableAutoCustomRBXAnimationIds
AnimationsServer.EnableAutoCustomRBXAnimationIds: falseIf set to true, applies the AutoCustomRBXAnimationIds module table to each player character on spawn.
AnimatedObjectsDebugMode
AnimationsServer.AnimatedObjectsDebugMode: falseIf set to true, prints will be made to help debug attaching and detaching animated objects.
PreloadAsyncProgressed
AnimationsServer.PreloadAsyncProgressed: RBXScriptSignalFires when ContentProvider:PreloadAsync() finishes pre-loading one animation instance.
-- In a ServerScript
Animations.PreloadAsyncProgressed:Connect(function(n, total, loadedAnimInstance)
print("ContentProvider:PreloadAsync() finished pre-loading one:", n, total, loadedAnimInstance)
end)
added in version 2.0.0-rc1
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).
INFO
Should be called once before any other method.
EquipAnimatedTool
BetaAnimationsServer:EquipAnimatedTool() → ()Equips the tool for the player_or_rig and then attaches the motor6d found in the AnimatedObjects folder to it.
CAUTION
This method is in beta testing. Use with caution.
added in version 2.4.0
GetTrackStartSpeed
Returns the animation track's StartSpeed (if set in HasProperties) or nil.
added in version 2.3.0
GetTimeOfMarker
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. YieldsBetaAnimationsServer:GetTimeOfMarker(markerName: string) → number?
The only reason this would yield is if the
initialization process that caches all of the marker
times is still going on when this method gets called. If
after 3 seconds the initialization process still has not
finished, this method will return nil.
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)
INFO
You must first modify your
AnimationIds module to specify
which animations this method will work on.
CAUTION
This method is in beta testing. Use with caution.
added in version 2.1.0
GetAnimationIdString
Returns the animation id string under rigType at path in the AnimationIds module.
local animIdStr = Animations:GetAnimationIdString("Player", "Run")
print(animIdStr) --> "rbxassetid://89327320"
added in version 2.1.0
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, `enemyCharacter` would have to be registered (on the server) and "Blocking" would need to be a valid animation name defined in the `AnimationIds` module.
local isBlocking = Animations:FindFirstRigPlayingTrack(enemyCharacter, "Blocking")
if isBlocking then
warn("We can't hit the enemy, they're blocking!")
end
added in version 2.1.0
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.
TIP
Especially useful on the client if the animation needs time to replicate from server to client and you want to specify a maximum time to wait until it replicates.
added in version 2.1.0
GetAppliedProfileName
Returns the player_or_rig's currently applied animation profile name or nil.
added in version 2.0.0
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.
-- In a ServerScript
local loadedAnimInstances = Animations:AwaitPreloadAsyncFinished()
print("ContentProvider:PreloadAsync() finished pre-loading all:", loadedAnimInstances)
added in version 2.0.0-rc1
Register
Registers the player's character/rig so that methods using animation tracks can be called.
NOTE
All player characters get automatically registered through player.CharacterAdded events.
TIP
Automatically gives the character/rig an attribute "AnimationsRigType" set to the rigType.
added in version 2.0.0-rc1
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.
added in version 2.0.0-rc1
IsRegistered
Returns if the player_or_rig is registered.
added in version 2.0.0-rc1
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.
TIP
See ApplyAnimationProfile() for a more convenient way of overriding default roblox character animations.
-- In a ServerScript
local Animations = require(game.ReplicatedStorage.Animations.Package.AnimationsServer)
Animations:Init()
task.wait(5)
print("Applying r15 ninja jump & idle animations")
-- These animations will only work if your character is R15
Animations:ApplyCustomRBXAnimationIds(game.Players.YourName, {
[Enum.HumanoidRigType.R15] = {
jump = 656117878,
idle = {
Animation1 = 656117400,
Animation2 = 656118341
}
}
})
GetAnimationProfile
AnimationsServer:GetAnimationProfile(animationProfileName: string) → animationProfilehumanoidRigTypeToCustomRBXAnimationIds?Returns the humanoidRigTypeToCustomRBXAnimationIds table found in the profile module Deps.<animationProfileName>, or not if it doesn't exist.
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.
NOTE
The player_or_rig does not need to be registered or have its tracks loaded for this to work.
WARNING
This function only works for players and R6/R15 NPCs that have an "Animate" script in their model.
INFO
For more information on setting up animated objects check out animation profiles tutorial.
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.
changed in version 2.0.0-rc1
Renamed: -> AwaitLoadedAwaitAllTracksLoaded
-- In a ServerScript
-- [WARNING] For this to work you need animation ids under the rig type of "Player" in the 'AnimationIds' module
local Animations = require(game.ReplicatedStorage.Animations.Package.AnimationsServer)
Animations:Init({
AutoLoadAllPlayerTracks = true -- Defaults to false
})
local player = game.Players:WaitForChild("MyName")
Animations:AwaitAllTracksLoaded(player)
print("Animation tracks finished loading on the server!")
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.
added in version 2.0.0-rc1
AreAllTracksLoaded
Returns if the player_or_rig has had all its animation tracks loaded.
changed in version 2.0.0-rc1
Renamed: -> AreTracksLoadedAreAllTracksLoaded
AreTracksLoadedAt
Returns if the player_or_rig has had its animation tracks loaded at path.
added in version 2.0.0-rc1
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.
changed in version 2.0.0-rc1
Renamed: -> LoadTracksLoadAllTracks
If player_or_rig is a rig, this requires Animations:Register() before usage.
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.
added in version 2.0.0-rc1
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.
changed in version 2.0.0-rc1
Renamed: -> StopAllTracksStopPlayingTracks
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:
-- In ReplicatedStorage.Animations.Deps.AnimationIds
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
}
}
}
-- In a ServerScript
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.
AttachAnimatedObject
BetaAttaches the animated object to the player_or_rig.
TIP
Enable initOptions.AnimatedObjectsDebugMode for detailed prints about animated objects.
INFO
For more information on setting up animated objects check out animated objects tutorial.
CAUTION
This method is in beta testing. Use with caution.
changed in version 2.4.0
You can no longer attach animated objects of type "motor6d only" (explanation).
DetachAnimatedObject
BetaDetaches the animated object from the player_or_rig.
TIP
Enable initOptions.AnimatedObjectsDebugMode for detailed prints about animated objects.
INFO
For more information on setting up animated objects check out animated objects tutorial.
CAUTION
This method is in beta testing. Use with caution.