Animation:Play() is not playing, no idea why

Hi! I’m making a tower defense minigame and right now I’m designing the enemies/monsters. I have a walk animation for my monster but my script won’t play it.

local hum = script.Parent
local par = hum.Parent
local servstor = game:GetService("ServerStorage")
local spawnstartanim = hum:WaitForChild("SpawnStartAnim")
local walkanim = ((servstor:WaitForChild("TDAnims")):WaitForChild("Enemy")):WaitForChild("UmbraMonstrumWalk")
local walkanimation = hum:LoadAnimation(walkanim)
walkanimation.Looped = true
spawnstartanim.Event:Connect(function()
	walkanimation:Play()
end)

What’s inside the model:
Screen Shot 2022-09-24 at 1.08.59 PM
What’s under the humanoid:
Screen Shot 2022-09-24 at 1.09.38 PM
None of the parts are anchored and they have cancollide off.
Please explain it clearly too.
Thanks for helping

2 Likes

Is there any errors or can you try printing the variables that you have and see if any returns nil.

local hum = script.Parent
local par = hum.Parent
local servstor = game:GetService("ServerStorage")
local spawnstartanim = hum:WaitForChild("SpawnStartAnim")
local walkanim = ((servstor:WaitForChild("TDAnims")):WaitForChild("Enemy")):WaitForChild("UmbraMonstrumWalk")
local walkanimation = hum:LoadAnimation(walkanim)
print(walkanimation)
walkanimation.Looped = true
spawnstartanim.Event:Connect(function()
	print("Event fired")
	walkanimation:Play()
end)

Screen Shot 2022-09-24 at 1.19.51 PM
The animation exists and the event has been fired, what’s wrong?

1 Like

I mean this worked for me, so it could be something with your remote.

local Humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
local IdleAnim = Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Idle)
IdleAnim:Play()
1 Like

I’m not using a remote event, and I tried using plain old

local hum = script.Parent
local par = hum.Parent
local servstor = game:GetService("ServerStorage")
local spawnstartanim = hum:WaitForChild("SpawnStartAnim")
local walkanim = ((servstor:WaitForChild("TDAnims")):WaitForChild("Enemy")):WaitForChild("UmbraMonstrumWalk")
local walkanimation = hum:LoadAnimation(walkanim)
print(walkanimation)
walkanimation.Looped = true
walkanimation:Play()

Everything I need exists

But the monster is still idle
Screen Shot 2022-09-24 at 1.28.56 PM

Oh then that’s my bad, so what is “spawnstartanim”?

It’s a BindableEvent
https://developer.roblox.com/en-us/api-reference/class/BindableEvent
It’s okay if you can’t find a solution, hopefully someone else can help

No I get it, It’s not hard to work with BindableEvent, and as well it worked for me, so it has to be with your model or an simple mistake.

local Humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
local IdleAnim = Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Idle)
local BindEvent = game.ReplicatedStorage.Event

BindEvent.Event:Connect(function()
	IdleAnim:Play()
end)

BindEvent:Fire()

It’s probably just my game… I’ll give you the place file so you can check if there’s anything wrong
TowerDefenseMinigame.rbxl (114.1 KB)

If anyone will reply, I will be out for a few hours. Thank you :slight_smile:

Nevermind, i dont know what is it yet

It might be the case that you use WaitForChild instead of FindFirstChild, its pretty poor performant in some cases and it might be the one

WaitForChild will yield the thread right? I don’t think that’s the problem because it still prints “Walk”…

What is the current animation priority? Make sure it is beyond these options:

  • action
  • action (1 - 4)
local hum = script.Parent
local animcontroller = hum:WaitForChild("AnimationController")
local anim = hum:WaitForChild("Walk")
local spawnstartanim = hum:WaitForChild("SpawnStartAnim")
local walkanimation = animcontroller:LoadAnimation(anim)
print(walkanimation)
walkanimation.Looped = true
walkanimation.Priority = Enum.AnimationPriority.Action2
walkanimation:Play()

If it’s supposed to be like this, it doesn’t work, no errors

local hum = script.Parent
local animcontroller = hum:WaitForChild("AnimationController")
local anim = hum:WaitForChild("Walk")
local spawnstartanim = hum:WaitForChild("SpawnStartAnim")
local walkanimation = animcontroller:LoadAnimation(anim)
print(walkanimation)
walkanimation.Looped = true
walkanimation.Priority = Enum.AnimationPriority.Action2
print("About to play anim")
walkanimation:Play()
print("a")

Screen Shot 2022-09-25 at 6.47.33 AM

The script will run in server storage, and the animations probably won’t keep playing once the model has been moved from server storage to the workspace. Just a thought.

I did try using bindable events but that didn’t work out. I didn’t try bindable events with the set priority so I’ll try that.

My script does actually run, it’s the :Play() that’s the problem

Yeah, been testing around with the .rbxl place file.

Turns out, when I print out the playing animation tracks on the animator, it says that the walk animation is playing.

local hum = script.Parent
local animcontroller = hum:WaitForChild("Animator")
local anim = hum:WaitForChild("Walk")
local par = hum.Parent
local servstor = game:GetService("ServerStorage")
local spawnstartanim = hum:WaitForChild("SpawnStartAnim")
local walkanim = ((servstor:WaitForChild("TDAnims")):WaitForChild("Enemy")):WaitForChild("UmbraMonstrumWalk")
local walkanimation = animcontroller:LoadAnimation(anim)

print(walkanimation)

walkanimation.Looped = true
walkanimation:Play()

print(animcontroller:GetPlayingAnimationTracks())

spawnstartanim.Event:Connect(function()
	print("Event fired")
	walkanimation:Play()
	print(animcontroller:GetPlayingAnimationTracks())
end)

Capture
Weird.
I’ll work on it more.

1 Like

Yeah, even constantly printing the table in a while loop doesn’t give me any answers.
It still says that the animations are playing in every table it prints out…