I am using an Animation Controller to animate custom models that are attached to the player and that the player controls. The AnimationController and all of the Animation instances are created server-side, and the input by the user is done locally and sent to play the animations on the server with Remote Events.
However, for a long time there have been subtle glitches with the animations causing some parts of the model to not move properly. On the player’s client, their model looks normal, but on the server, only half of their model is moving the right way. All of the parts in the custom model are connected with Motor6D and all connect to the PrimaryPart of the model.
I’ve read on the Wiki that using AnimationController or Humanoid to animate a locally controlled model might cause some undesired effects:
If an
AnimationController
is created on the server, its animations should be loaded and played on the server unless a player has been assigned network ownership of theModel
's root part usingBasePart:SetNetworkOwner
. If anAnimationController
is created on the client it should be animated by the client.Although it is not recommended, if a developer wishes to play animations on a locally controlled
Model
from the server they can use theAnimator
object. -ROBLOX WIKI
So, after reading this, this is what I’ve done to try to solve the issue:
-
I tried to load the Controller and the Animations only locally, but then the problem was only the player could see the animation from the client, and no one else server-wide could see it.
-
I also tried to set the NetworkOwner of the primary part of the custom model to the server. The output doesn’t give any sort of error, but the animations simply stop working altogether, client and server. The custom character’s NetworkOwner is the player’s client by default since it’s Parented to the player’s character.
This is the script I’m currently using that’s causing these issues:
LOCAL SCRIPT (located in PlayerGui):
local actions = (morph):WaitForChild("Actions")
local FireWalk = actions:WaitForChild("Walk")
Player.Character.Humanoid.Running:connect(function(speed)
if speed > 3 and not walking then
walking = true
FireWalk:FireServer(tween) --Fires Remote Event to start the Walking animation
elseif speed < 3 and walking then
walking = false
FireWalkStop:FireServer(tween) --Fires Remote Event to stop the walking animation
end
end)
SERVER SCRIPT (located on the Player’s custom character model):
local actions = script.Parent:WaitForChild("Actions")
local FireWalk = actions:WaitForChild("Walk")
FireWalk.OnServerEvent:Connect(function(player,tween)
local Walk = script.Parent.AnimationController.Walk
local WalkTrack = script.Parent.AnimationController:LoadAnimation(Walk)
WalkTrack:Play(tween/2)
end)
FireWalkStop.OnServerEvent:Connect(function(player,tween)
local AnimCont = script.Parent.AnimationController
for _,WalkTrack in pairs(AnimCont:GetPlayingAnimationTracks()) do
if WalkTrack.Animation == script.Parent.AnimationController.Walk then
WalkTrack:Stop(tween/2)
end
end
end)
This script produces no error and works fine, but sometimes there are subtle glitches in the character models’ animations, and sometimes they are very noticeable.
I also read this article: Animator | Documentation - Roblox Creator Hub , but I am having a hard time understanding what it means. It’s suggesting that the Animator instance automatically replicates client-controlled models to the server, but it was not the case for me since in my previous attempt to load the animations locally, only the client could see it. If someone could explain this to me it would be very helpful!!!