-- local animation = Instance.new("Animation") -- What i would do is just create an animation object inside the rig or somewhere else, but for this situation i will assume its outside the rig
-- I don't know where the NPC is so i will asume its in workspace
local anim = workspace:FindFirstChild("NPCAnim")
local npc = workspace:FindFirstChild("DefaultNPC"):FindFirstChildOfClass("Humanoid")
local loadedAnim = npc:LoadAnimation(anim)
loadedAnim:Play()
local Humanoid = NewNPC.Humanoid
local anim = game.ReplicatedStorage.Animations.NPCAnimations.Stand
local loadedAnim = Humanoid:LoadAnimation(anim)
loadedAnim:Play()
as it’s being deprecated, place an “Animator” below your NPC’s Humanoid either manually or through the script.
In your script:
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=507766388"
NewNPC:FindFirstChildOfClass("Humanoid"):LoadAnimation(animation):Play()
You’re creating a new animation, but don’t appear to be parenting it to anything. You can either parent it by doing:
local animation = Instance.new("Animation",NewNPC:WaitForChild("Humanoid"))
--Or
local animation = Instance.new("Animation")
animation.Parent = NewNPC:WaitForChild("Humanoid")
We then want to load the animation to the animator which we can do the same way as loading it to the humanoid.
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507766388"
animation.Parent = NewNPC:WaitForChild("Humanoid")
local loadedAnimation = NewNPC.Humanoid:WaitForChild("Animator"):LoadAnimation(animation)
We can then go ahead and play the animation just like you always would.
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507766388"
animation.Parent = NewNPC:WaitForChild("Humanoid")
local loadedAnimation = NewNPC.Humanoid:WaitForChild("Animator"):LoadAnimation(animation)
loadedAnimation:Play()
Ensure that your NPC is referenced correctly in your script. This will also just play the animation as soon as the script runs, but you can remove the loadedAnimation:Play() and place it wherever in your script to trigger the animation on the NPC.
I’ve setup my script and NPC to match yours in a game, to ensure functionality. If this script isn’t working for you you’ve done something wrong, and i’ll be glad to help you get the issue fixed.