Animation won't play using a LocalScript

Try loading them on the Humanoid, I believe documentation states it will automatically create a Animator to load the animations on.

2 Likes

Still doesn’t work for me. No error messages or anything and the animation still doesn’t play.

1 Like

Local scripts have to be a descendant of the client’s player object or the client’s character. Because it is in its own object, the scripts will not work in this situation.

1 Like

But it still runs and reacts to the OnClientEvent. Is it just the animations that won’t work if it’s not a descendant of the player?

I was wrong, local scripts have to be a descendant of the client’s player object or the client’s character, but they also work in ReplicatedFirst. Your script is probably still active in ReplicatedFirst instead of inside the workspace.

Did you ensure the animation priority is high enough and if the remote events are actually being ran?

1 Like

There is already an animator inside the humanoid but you might have to use a waitforchild to get it.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AnimationsFolder = ReplicatedStorage:WaitForChild("Animations")
local Idle = AnimationsFolder.IdleAnim
local Walk = AnimationsFolder.WalkAnim
local Wave = AnimationsFolder.WaveAnim

local char = script.Parent
local Humanoid = char.Humanoid

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayNPCWave = ReplicatedStorage.PlayNPCWave

local animator = humanoid:WaitForChild("Animator")

local IdleAnim = animator:LoadAnimation(Idle)
local WalkAnim = animator:LoadAnimation(Walk)
local WaveAnim = animator:LoadAnimation(Wave)

IdleAnim.Priority = Enum.AnimationPriority.Idle
WalkAnim.Priority = Enum.AnimationPriority.Movement


PlayNPCWave.OnClientEvent:Connect(function()
	IdleAnim:Play()
	
end)
1 Like

Yes, the priority is high enough, we also tried with the Action4 priority but no change in result. The remote event works

It still didn’t work unfortunately.

did any errors appear in the console?

Nope, there’s no error in the console at all

did you check to make sure that the line even runs with a print or something?

Yes we did try printing and it works!

Try running a loop on the animator to check if it reads that a animation actually plays. That will better help you.

1 Like

i’m unsure how to do that. what do you mean?

I really haven’t tried it, but its along the lines of this:

local Animator = script:FindFirstChildOfClass('Animator') --Change This
for __, AnimationTrack in pairs(Animator:GetPlayingAnimationTracks()) do
	print(__, AnimationTrack)
end

There’s one random animation that pops up just when I use the LocalScript to play, “Animation1” or “Animation2”. But when I play it in a server script it’s just the IdleAnimation that is playing.

Most likely a replication issue? Try running the animation on the server just to see.

Yes, the animation runs on the server, just not on the client at all. The thing is that I need to be able to use the .IsPlaying but that doesn’t replicate in a server script.

1 Like

First of all, please do not try playing the animations via Humanoid:LoadAnimation() and AnimationController:LoadAnimation as it can lead to replication issues. That’s why both methods were deprecated years ago, as stated here:

I recommend you to refrain to using the Animator included in the characters Humanoid, it’s there for a reason.

And there might also be conflicts because now you have 2 Animators as you create a new one and put it in the exact same path of the already auto-generated one. Please try loading it on the pre generated animator and tell us what’s happening exactly.