Character plays an animation on hit

So I am trying to script a combo system but to start off I need to character that gets hit to play a hit animation, for some reason my current script won’t work, and it doesn’t say anything in the output.

local Debounce = true
 RegRay.FireBeam.Touched:Connect(function(h)
  if h.Parent:FindFirstChild('Humanoid') and h.Parent.Name ~= plr.Name and Debounce then 
local ID = "rbxassetid://5207615951"
			

local HitHRP = h.Parent.HumanoidRootPart
local PlrHRP = plr.Character.HumanoidRootPart
			
local HitHumanoid = h.Parent:FindFirstChild("Humanoid")	
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://5207615951"
local Animation = HitHumanoid:LoadAnimation(Anim)
Animation:Play()		

local HitBV = Instance.new("BodyVelocity")
HitBV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
HitBV.P = 100
HitBV.Velocity = PlrHRP.CFrame.lookVector*45


HitBV.Parent = HitHRP

game.Debris:AddItem(HitBV, .5)
	Debounce = false   
   local Enemy = h.Parent.Humanoid
   Enemy:TakeDamage(5)
   wait(0)
   Debounce = true
  end
 end)

Thank you for your time :slightly_smiling_face:

1 Like

First off I wouldn’t use Instance.new() for stun anims, I would just have it somewhere and load it in the humanoid from there. If that doesn’t fix it try playing the animation on client.

2 Likes