What do you want to achieve? Keep it simple and clear!
I am using an NPC I found in the Toolbox which has its own “stab” animation that is part of the script and is used when the NPC attacks players. I created a “slump” animation in Animation editor that I would like to load in the NPC when a player punches the NPC.
What is the issue?
When a player punches the NPC the slump animation doesn’t work. Nothing happens.
What solutions have you tried so far?
I created a slump animation in Animation editor, added the Animation to the NPC model, and entered the animation Id (http://www.roblox.com/Asset?ID=8381045470) in the properties tab. Then I defined the new animation in the NPC script:
--Existing Animation already in model / script
local stabAnimation = myHuman:LoadAnimation(script.Parent.Stab)
stabAnimation.Priority = Enum.AnimationPriority.Action
--New Animation I created and added by me
local slumpAnimation = myHuman:LoadAnimation(script.Parent.Slump)
slumpAnimation.Priority = Enum.AnimationPriority.Action
Then I added a Bindable Event function in to the script to load the animation when the NPC is punched
I’ve done some experimenting to zero in on the problem:
Since the Slump Animation wasn’t working, I was curious if it was an Animation issue versus a coding issue. So I simply replaced the Slump AnimationId in the properties tab of the Animation with the stab Animation Id and when the NPC is punched it makes a stabbing motion. This tells me my code is correct and must be something to do with the slump animation itself.
When a player punches another player (instead of an NPC), the slump animation works. This tells me the animation and animation Id works.
I cannot identify what the problem is. Any help would be greatly appreciated!
What I shared above wasn’t meant to be a link - it’s what I entered into the AnimationId portion of properties and believe it’s the correct formatting (and the same as the stab animation that works).
yes I saw your suggestion. Based on a post on this topic I added an Animator to the humanoid of the NPC. Then wrote this code:
local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
local slumpAnimation = animator:LoadAnimation(script.Parent.Slump)
slumpAnimation.Priority = Enum.AnimationPriority.Action
slumpAnimation:Play()
return slumpAnimation
end
thank you for this suggestion. The lowercase “asset” doesn’t help and the other animation that works (“stab”) uses “Asset” also. About the animation controller, I did use it (see code above). Your suggestion is different which is to replace it with humanoid rather than putting it inside humanoid. My concern with this is that I have other scripts that rely on identifying the Humanoid inside the NPCs.
I would not set the animation priority via script. Set it in the animation editor. One less thing to worry about going wrong (and it currently does not work as expected, Priority does not load properly for up to a second). This should not affect your animation, but better to fix now.
I know you have one working animation using the other format, but when I look at all my Animation objects, the default format set by Roblox looks like this:
rbxassetid://8381045470
Something else to try? Also, this is how I set up my game services: