Animation playback problem

local airHit = {
	"rbxassetid://13305219902", -- AIR UP
	"rbxassetid://13305215113", -- AIR DOWN
}
local function airUp()
	
	local currentTarget: Humanoid = nil
	
	local function OnTouched(otherPart)
		if otherPart.Name == "Head" or "Torso" and otherPart.Parent:FindFirstChild("Humanoid") ~= nil and inCombat.Value == true then
			currentTarget = otherPart.Parent:FindFirstChild("Humanoid")
		end
	end
	
	humanoid.Touched:Connect(OnTouched)
	
	local hitAnimation = Instance.new("Animation")
	hitAnimation.AnimationId = airHit[1]
	print(hitAnimation)

	local currentTarget = currentTarget
	print(currentTarget)

	local loadHit = currentTarget:LoadAnimation(hitAnimation)
	wait(1)
	loadHit:Play()
	print(loadHit)
end

So here I have a script that plays the animation in the enemy, it if anything is activated, I just did not see the point in showing you part of the script activation.

So this is the script you play the animation in the enemy, but for some reason there is such an error:

1 Like

currentTarget is nil

1 Like

But when I wrote the print in the touched function itself, it said that currentTarget = humanoid. Then how do I pass the humanoid outside of the touched function?

1 Like