Does not want to play the animation in the script

local airHit = {
	"rbxassetid://13305219902", -- AIR UP
	"rbxassetid://13305215113", -- AIR DOWN
}
if data.Air == "Up" then
			
			local hitAnimation = Instance.new("Animation", workspace.Fx)
			hitAnimation.AnimationId = airHit[1]
			print(hitAnimation)
			
			local currentTarget = data.Target.Humanoid

			local loadHit = currentTarget:LoadAnimation(hitAnimation)
			loadHit:Play()
end

So I have a script that when the rise of the NPC is played in his animation, attention here is not the whole script I gave you only part of which is responsible for animation. The problem is that the NPC rises but no animation in what is the problem?

1 Like

Unless there is a problem in a separate script or somewhere else within this one, this should work. Although, roblox often gets upset whenever you set the parent of a newly created instance in the same line as you created it in. In this case, it isn’t necessary to set a parent to the animation instance at all, so just do the following:

...
local hitAnimation = Instance.new("Animation")
...

I did as you showed but nothing changed)

It’s likely a problem outside of this snippet of code then.

Just understand that the code itself works and yet before I tried to run it all in a local script so it also did not work. I searched for more information on devforum and saw this…

for i,v in pairs(game.Workspace.NPCS:GetChildren()) do -- all the npcs
	v.Touched:Connect(function() -- npc when touched
		local Animation = Instance.new("Animation") -- creates the animation
		Animation.AnimationId = "rbxassetid://0" -- your animation id
		local Humanoid = v:FindFirstChild("Humanoid") -- npcs with humanoid
		local animtrack = Humanoid:LoadAnimation(Animation) -- load the animation
		wait(1) -- wait
		animtrack:Play() -- Play your animation
	end)
end

This is a sample code and the person there says it should work. Can the problem be that I don’t have an animator for the NPС?

I don’t imagine that it’s the issue, but you can try adding an Animator object into the Humanoid if you think that could be the issue

Okay, but do you think there are other ways to play the animation in the NPC?