Animation not playing for my npc

I’m trying to play an animation when my enemy attacks someone, but the animation isn’t playing. The default Roblox animate script is also included in here, I figured that might be the problem and messed with the weights but there were no results.

My script:

local repStorage = game.ReplicatedStorage
local quantityManager = require(repStorage.QuantityManager)
local humanoid = script.Parent.Zombieoid --humanoid is renamed for anti team kill
local rarm = script.Parent:FindFirstChild("Right Arm")
local larm = script.Parent:FindFirstChild("Left Arm")
local zombie = script.Parent
local hum = zombie.Zombieoid
local animation = script:WaitForChild("Attack")
local animationTrack = humanoid:LoadAnimation(animation)
local debounce = 0
local deathsound = zombie.HumanoidRootPart.DeathSound
local attacksound = zombie.HumanoidRootPart.AttackSound
local pitch = deathsound.PitchShiftSoundEffect
animationTrack.Priority = Enum.AnimationPriority.Action

function dmg(hit)
	if hum.Health ~= 0 then
		if debounce == 0 then
			if hit.Parent ~= nil then
				local hum = hit.Parent:findFirstChild("Humanoid")
				if hum ~= nil then
					debounce = 1
					hum:TakeDamage(10)
					animationTrack:Play()
					attacksound:Play()
					wait(1)
					debounce = 0
				end
			end
		end
	end
end

The damage function is run when the enemy is touched, and I’m sure it’s activating because I take damage.
Any help would be appreciated, thanks :slight_smile:

at the top line of the function it requires the humanoids health to be 0. So it cant move on until the player has died. Try removing it

The top line is to make sure it’s not dead; notice the tilde. Also I’m sure it advances past since the the other parts of the function work (sound damage etc)

if there is another animation already running on the zombie like a run animation, it could be canceling out the attack animation

i had a similar problem in my game

If that’s the case, how would I give my animation priority over the others?

I dont know if that would work what i did is i moved my attack animation to the same script as the other animation and did this
script.Parent.Activated:Connect(function()
animtrack:Stop()
if debounce then
debounce = false
animtrack1:Play()
wait(.8)
animtrack:Play()
debounce = true
end
end)

The issue with that is that I want my other (walking) animation to overlap with the one I’m trying to play, I know it’s possible because I’ve seen it in other games before.

Well good luck, and don’t give up

That’s the plan :+1:
I’ll keep going at it, thanks for the time :slight_smile:

1 Like